In Python, is there a way to sort a list made of lists and tuples, consistently? -
sort of a
, b
expected me, why c
different? there ways make consistent a
, b
, without converting either lists or tuples?
>>> = [(1, 0), (0, 0)] >>> a.sort() >>> print [(0, 0), (1, 0)] >>> >>> b = [[1], (0)] >>> b.sort() >>> print b [0, [1]] >>> >>> c = [[1, 0], (0, 0)] >>> c.sort() >>> print c [[1, 0], (0, 0)] >>>
it's possible convert them purpose of sorting:
>>> c = [[1, 0], (0, 0)] >>> c.sort(key=tuple) >>> c [(0, 0), [1, 0]]
that being said, list containing mix of lists , tuples code smell.
Comments
Post a Comment