Sorting a meta-list by first element of children lists in Python
Posted
by
thismachinechills
on Stack Overflow
See other posts from Stack Overflow
or by thismachinechills
Published on 2013-07-03T16:47:20Z
Indexed on
2013/07/03
17:05 UTC
Read the original article
Hit count: 203
I have a list, root
, of lists, root[child0]
, root[child1]
, etc.
I want to sort the children of the root list by the first value in the child list, root[child0][0]
, which is an int
.
Example:
import random
children = 10
root = [[random.randint(0, children), "some value"] for child in children]
I want to sort root
from greatest to least by the first element of each of it's children.
I've taken a look at some previous entries that used sorted()
and a lamda
function I'm entirely unfamiliar with, so I'm unsure of how to apply that to my problem.
Appreciate any direction that can by given
Thanks
© Stack Overflow or respective owner