Using namedtuples field names for column indices in a list of lists

Paul Rudin paul.nospam at rudin.co.uk
Sun Jan 8 09:48:41 EST 2017


"Deborah Swanson" <python at deborahswanson.net> writes:
> Peter Otten wrote, on January 08, 2017 3:01 AM
>>>> columnA = [record.A for record in records]
>> This is very neat. Something like a list comprehension for named tuples?

Not something like - this *is* a list comprehension - it creates a list
of named tuples.
The thing you iterate over within the comprehension can be any
iterator. (Of course you're going to run into problems if you try to
construct a list from an infinite iterator.)


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /