def dictrev():
prompt = "Enter the key and value of a dictionary like this: 'key:value':"
list = [];list_rev = [];i = 0
while True:
element = raw_input(prompt).strip().split(':')
if element == ['.']:
break
list.append([]);list_rev.append([])
print element
print list(reversed(element))
list[i] = element
list_rev[i] = list(reversed(element))
i += 1
print 'The dictionary you input is:'
print dict((list))
print '\nThe dictionary whose key and value are reversed is:'
print dict((list_rev))
dictrev()
这是Core编程7-7中的问题代码。
然而,当我运行这个程序时,我得到了一个TypeError:'list‘对象在代码中不是可调用的
print list(reversed(element))
我所做的工作如下:
l = ['a','b']
print l
print list(reversed(l))
没有什么像'list对象不可调用‘这样的错误。我很困惑!
我已尽我所能解决这个问题。谢谢大家的帮助。
发布于 2016-07-09 02:14:10
看看这一行:
list = []
您重写了内置的list
类型
https://stackoverflow.com/questions/38277609
复制相似问题