Wednesday, February 10, 2016

2 different kinds of "list" in Python

When using pdb in python 3 you might encounter this odd error:

(Pdb) my_dict[some_key]
{'some_key': }

(Pdb) type(my_dict[some_key])

(Pdb) list(my_dict[some_key])
*** Error in argument: '(my_dict[some_key])'
How come? That's because "list" here is a method of "pdb" and not the the operator "list" of Python. To fix it, you can do this:

(Pdb) a1 = list(my_dict[some_key])
Now "a1" is, endeed, a list.

(Pdb) print(a1)
['a', 'cc', 'e', 'some_other_key']

No comments :

Post a Comment