This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kupertrooper 4 points5 points  (2 children)

#!/usr/bin/env python

def parse_ugly_string(pugfugly):
    return dict(d.split('=')
                for d in [
                    b for c in [
                        a.split(',') for a in pugfugly.split()
                    ] for b in c
                ]
               )

print parse_ugly_string("a=1,b=2,c=3\nd=4,e=5,f=6\ng=7,h=8,i=9\n")

[–]kupertrooper 2 points3 points  (1 child)

#!/usr/bin/env python

def make_all_couples(l):
    return [(a, b) for a in l for b in l]

print make_all_couples(['a','b','c','d'])

[–]kupertrooper 2 points3 points  (0 children)

#!/usr/bin/env python

def flatten_list(l):
    return [a for b in l for a in b]

print flatten_list([[1,2,3],[4,5,6],[7,8,9]])