Sorting dict by value w/ operator.itemgetter- using key name?
Terry Reedy
tjreedy at udel.edu
Thu Jul 30 17:02:20 EDT 2009
Wells Oliver wrote:
> Bit of code:
>
> print sorted(results.items(), key=operator.itemgetter(1))
>
> Would rather use 'H9', which is the name of the key in position 1 like:
>
> print sorted(results.items(), key=operator.itemgetter('H9'))
>
> Obviously that ain't work else I wouldn't be sending this email. Any tips?
Suppose namepos=['H9':1,} etc, then itemgetter(namepos['H9'])
More information about the Python-list
mailing list