Flatten a list/tuple and Call a function with tuples
Paul Rubin
http
Wed Jul 25 12:33:26 EDT 2007
beginner <zyzhu2000 at gmail.com> writes:
> I know the * operator. However, a 'partial unpack' does not seem to work.
A few other posters have mentioned ways around this, but you might ask
yourself what coding situation makes you want to do this stuff in the
first place. I won't say there's never a reason for it, but a lot of
times, a list containing a mixture of scalars and lists/tuples is a
sign that your underlying data representation is contorted. Things
are logically single values or they are logically lists of values, and
that mixed representation is often a sign that the item logically
should be a list, and you're hairing up the program with special
treatment of the case where the list has exactly one element.
I.e. instead of [[1,2,], 3, [5,6,]] maybe you really want
[[1,2,], [3,], [5,6]] without the special treatment and flattening.
More information about the Python-list
mailing list