Re: Python3: Using sorted(key=...)

2009-08-06 Thread Paul Rubin
Johannes Bauer writes: > def myorder(x): > if type(x[0]) == int: > return x[0] > else: > return x[0][0] I used to write code like that pretty regularly, but over time I found that it's better to stay consistent and use the same container format (in this case, tuples) f

Re: Python3: Using sorted(key=...)

2009-08-06 Thread Johannes Bauer
MRAB schrieb: > Johannes Bauer wrote: >> Hello list, >> >> I'm having trouble with a incredibly simple sort of a list containing >> ints and tuples: >> >> def myorder(x): >> if type(x) == int: >> return x >> else: >> return x[0] >> >> odata = sorted([ (a, b) for (a, b) in da

Re: Python3: Using sorted(key=...)

2009-08-06 Thread MRAB
Johannes Bauer wrote: Hello list, I'm having trouble with a incredibly simple sort of a list containing ints and tuples: def myorder(x): if type(x) == int: return x else: return x[0] odata = sorted([ (a, b) for (a, b) in data["description"].items

Python3: Using sorted(key=...)

2009-08-06 Thread Johannes Bauer
Hello list, I'm having trouble with a incredibly simple sort of a list containing ints and tuples: def myorder(x): if type(x) == int: return x else: return x[0] odata = sorted([ (a, b) for (a, b) in data["description"].items() ], key=myorder) stil