transform a list of lists in a lit of strtings???

Skip Montanaro skip at pobox.com
Sun Sep 8 22:27:56 CEST 2002


    James> labels2 = [i for item in labels1 for i in item]

    James> (I find this oddly hard to read.)

I rarely use list comprehensions for anything complex, but for this sort of
thing I tend indent it:

    labels2 = [i for item in labels1
                     for i in item]

Which is to say, if it gets too complex, I more-or-less just fall back to
the statement form:

    label2 = []
    for item in labels1:
        for i in item:
            labels2.append(i)

:-)

-- 
Skip Montanaro
skip at pobox.com
consulting: http://manatee.mojam.com/~skip/resume.html




More information about the Python-list mailing list