Differences creating tuples and collections.namedtuples

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Feb 18 13:05:11 CET 2013

On 18 February 2013 12:03, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> On 18 February 2013 11:47, John Reid <johnbaronreid at gmail.com> wrote:
>> I'm seeing this problem because of the following code in IPython:
>> def canSequence(obj):
>>     if isinstance(obj, (list, tuple)):
>>         t = type(obj)
>>         return t([can(i) for i in obj])
>>     else:
>>         return obj
> What is the point of the code above? If obj is a list or a tuple you
> create a new list or tuple with the same data and then return it
> otherwise you just return the object. What about:

Sorry, I didn't read this properly. I see that you want apply can() to
all the elements. What is the reason for wanting to preserve the type
of the sequence?


More information about the Python-list mailing list