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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -