Python 2.7 exceptions.TypeError不可损坏的类型列表。我该如何解决这个问题?
好的,唯一对我不起作用的是视图函数。在我添加一个事件,然后我尝试查看它之后,我得到一个不可破坏的类型:“list”错误。这是为什么?我如何修复它?谢谢您正在分配Python 2.7 exceptions.TypeError不可损坏的类型列表。我该如何解决这个问题?,python-2.7,Python 2.7,好的,唯一对我不起作用的是视图函数。在我添加一个事件,然后我尝试查看它之后,我得到一个不可破坏的类型:“list”错误。这是为什么?我如何修复它?谢谢您正在分配x=dictionary.keys(),这意味着x是(字典中所有键的)列表。然后在dictionary中执行if x,询问键x是否是dictionary中的键。但是列表是可变的,所以不允许它是键 你是不是真的想说如果字典里的小时数是多少?这很有效谢谢!很抱歉我讨厌成为一个有着愚蠢问题的新程序员。 import time dictiona
x=dictionary.keys()
,这意味着x是(字典中所有键的)列表。然后在dictionary中执行if x,询问键x
是否是dictionary中的键。但是列表是可变的,所以不允许它是键
你是不是真的想说如果字典里的小时数是多少?这很有效谢谢!很抱歉我讨厌成为一个有着愚蠢问题的新程序员。
import time
dictionary = {}
def add():
x = int(raw_input("Please enter the hour of your event in 24 hour time"))
y = raw_input("Please enter the name of your activity")
dictionary[x] = y
print (dictionary[x] + " was added succesfully")
main()
def view():
theTime = time.localtime()
print "the hour is: ", theTime.tm_hour
theHour = theTime.tm_hour
x = dictionary.keys()
if x in dictionary:
print "The current event is", x
print "Your full shcedule for today is: ", dictionary
main()
def remove():
print dictionary
x = int(raw_input("which time slot would you like to clear?"))
z = dictionary.pop(x)
print z + " was removed"
main()
table = {
1 : add,
2 : view,
3 : remove
}
def run(x):
table[x]()
def main():
x = int(raw_input("Please select and option! \n\n1. Add an event \
\n2. View an event \n3. Remove an event \n4. Exit"))
if x == 4:
exit()
run(x)
main()