Linked Questions

62 votes
3 answers
94k views

Sorting list of lists by the first element of each sub-list [duplicate]

How to sort a list of lists according to the first element of each list? For example, giving this unsorted list: [[1,4,7],[3,6,9],[2,59,8]] The sorted result should be: [[1,4,7],[2,59,8],[3,6,9]]
Shubham Sharda's user avatar
9 votes
3 answers
27k views

Method to sort a list of lists? [duplicate]

I have a list of lists (can't be tuples since I have to generate it dynamically) and it is structured as a list of lists of one int and one float Like so: [[1,1.0345],[2,5.098],[3,4.89],[2,5.97]] I ...
njvb's user avatar
  • 1,377
2 votes
2 answers
3k views

Sorting datetime object in a list of tuples [duplicate]

i have a list of tuples which is like following [('John', datetime.datetime(2016, 11, 27, 18, 18), datetime.datetime(2017, 11, 27, 18, 18)), ('Adam', datetime.datetime(2017, 11, 27, 18, 18), datetime....
foret's user avatar
  • 337
1 vote
1 answer
241 views

Ordering a multidimensional array in python [duplicate]

I have a data structure like: [ ["id1", 123], ["id2", 1], ["id3", 6] ] and I would like to ordered it (descendingly) according to the second variable, like this: [ ["id1", 123], ["id3", 6], ["id2", ...
nunos's user avatar
  • 21k
0 votes
2 answers
648 views

Python - get element of list where value is the minimum of all elements [duplicate]

I have the following list: [[733.16584917887963, 123620000.0, 32111000.0, 301.0], [732.27472276611104, 123620001.0, 32111000.0, 302.3], [731.39029416733558, 123620002.0, 32111000.0, 303.3], [730....
Stefan's user avatar
  • 1,453
0 votes
1 answer
414 views

Sort nested list by second value [duplicate]

Input : [[0, 2], [1, 4], [2, 6]] Description : I need to print two lists with greater value by comparing the element in the 2nd place. Expected Output: [[1, 4], [2, 6]]
Santhosh's user avatar
  • 219
0 votes
1 answer
314 views

How to sort list within a list? [duplicate]

I want to sort my list based on the first item such as: fruits = \ [['Mango', 6, 5, 8.0], ['Banana', 2.0, 5, 8.9, 7], ['Pineapple', 4, 6.8, 9], ['Apple', 3.9, 6, 7, 2]] to be sorted out like this:...
Fynn Mahoney's user avatar
-2 votes
2 answers
478 views

Sort a list according to the sublists [duplicate]

I am given a list: lst = [[7090, 1.286], [7486, 2.569], [7571, 0.091]] I want to sort this list in ascending order according to the second numbers of the sublists (namely, 1.286, 2.569, 0.091) so it ...
End points's user avatar
-3 votes
1 answer
258 views

How to sort a list in python based on internal list? [duplicate]

I have a list as follow: list1 = [['10', 'John', 'python'], ['1', 'Sara', 'java'], ['3','Tom', 'C']] and as sorted result I expect following outpt: 3 Tom C 1 Sara Java 10 John python in fact I ...
Babak Memar's user avatar
0 votes
2 answers
109 views

Sorting(rearranging) the list [duplicate]

I have been struggling to sort or rearrange the lists. I would want to sort the lists in descending order based on the numbers(last element within the list). So, ideally, the list with (297539) will ...
Joker's user avatar
  • 29
0 votes
1 answer
83 views

How to sort list of lists using sorting key from inner lists? [duplicate]

I have a table that looks like this: list_ip=[ ['192.168.1.15', 10, 20], ['192.168.0.20', 15, 15], ['10.0.0.5', 50, 5], ['10.0.0.2', 55, 5]] The result should be: [['10.0.0.2', 55, 5], ['10....
gorte's user avatar
  • 23
-3 votes
1 answer
61 views

How do I sort a list of lists in python? [duplicate]

How would I make this code: [['Phil', 19], ['Billy', 8221], ['Jerald', 1], ['Bobby', 194]] Sorted by number into this code: [['Billy', 8221], ['Bobby', 194], ['Phil', 19], ['Jerald', 1]] I tried ...
Flynn1460's user avatar
0 votes
1 answer
37 views

Sort double dimensions list with a given column Python [duplicate]

I've started Python recently and came up with a project that gives me a 2 dimensions list. list = [ ['Symbol', 'Price', 'Number', 'Currency'], ['MSFT', '100', '25', 'USD'], ['AAPL', '200',...
BigBros's user avatar
0 votes
0 answers
22 views

Alphabetical organization of sublists in Python [duplicate]

I have a list that consists of contacts. For example: phones = [['Jerry', '(212) 745-3837'],['Elliot', '(212) 843-2724']] I need to sort it alphabetically so that it is: [['Elliot', '(212) 843-2724'...
Yxrym's user avatar
  • 11
64 votes
6 answers
63k views

Duplicate items in legend in matplotlib?

I am trying to add the legend to my plot with this snippet: import matplotlib.pylab as plt fig = plt.figure() axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # left, bottom, width, height (range 0 to 1) ...
user avatar

15 30 50 per page