[x]
is a list containing the element x
.
list(x)
takes x
(which must already be iterable!) and turns it into a list.
>>> [1] # list literal
[1]
>>> ['abc'] # list containing 'abc'
['abc']
>>> list(1)
# TypeError
>>> list((1,)) # list constructor
[1]
>>> list('abc') # strings are iterables
['a', 'b', 'c'] # turns string into list!
The list constructor list(...)
- like all of python's built-in collection types (set, list, tuple, collections.deque, etc.) - can take a single iterable argument and convert it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…