-1

I wrote the following code with Python but the terminal tells me "list object is not callable". Who know what's wrong with my code? Thanks!

c={"a": 10,"b":1,"c":22}
tmp=list()
for k,v in c.items():
    tmp.append((v,k))
print tmp
tmp.sort(reverse=True)
print tmp
  • 1
    Your code runs fine in python version `2.7.9`. Which version are you using? To find out, use `import sys` and `print(sys.version)` – gtlambert Feb 15 '16 at 21:54
  • unrelated: if you do not want to use a for loop, you can also create the list with a comprehension: `tmp = [t for t in c.items()]` – Pynchia Feb 15 '16 at 21:57
  • Your code works in python `2.7.6` and `3.4.3` – danidee Feb 15 '16 at 21:58
  • I would suggest `tmp = []` rather than `tmp = list()`. This will also, incidentally, fix the error. timgeb is correct, however, that you shouldn't use `list` as a variable name, because it conflicts with the built-in type. – zondo Feb 15 '16 at 22:42

1 Answers1

3

Somewhere in your code you have used the name list as a variable name and shadowed the built in list. Look for where you do that and choose a better name. As a temporary solution you can issue del list before tmp=list().

timgeb
  • 76,762
  • 20
  • 123
  • 145