how to construct a list of only one tuple
MRAB
google at mrabarnett.plus.com
Thu Nov 27 18:22:01 EST 2008
TP wrote:
> bearophileHUGS at lycos.com wrote:
>
>>>>>> a=("1","2")
>>>>>> b=[("3","4"),("5","6")]
>>>>>> list(a)+b
>>> ['1', '2', ('3', '4'), ('5', '6')]
>>>>> a = ("1", "2")
>>>>> b = [("3", "4"), ("5", "6")]
>>>>> [a] + b
>> [('1', '2'), ('3', '4'), ('5', '6')]
>
> Thanks a lot.
> Why this difference of behavior between list(a) and [a]?
>
list(a) iterates through its argument, building a list from the results.
In this case it iterates though the items in the tuple.
[a] just creates a list with a as an item.
More information about the Python-list
mailing list