Sort « tuple « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » tuple » Sort 

1. How does Python sort a list of tuples?    stackoverflow.com

Empirically, it seems that Python's default list sorter, when passed a list of tuples, will sort by the first element in each tuple. Is that correct? If not, what's the right ...

2. Creating a tree from a list of tuples    stackoverflow.com

I seem to be blind at the moment, so I need to ask here. I want to sort a list of tuples which look like that

(id, parent_id, value)
So that it is ...

3. Sorting a tuple that contains lists    stackoverflow.com

I have a similar question to this one but instead my tuple contains lists, as follows:

mytuple = (
 ["tomato", 3],
 ["say", 2],
 ["say", 5],
 ["I", 4],
 ["you", 1],
 ["tomato", 6],
)
What's ...

4. Why can't I sort this list?    stackoverflow.com

statlist = [('abc',5,1), ('bzs',66,1), ... ]
sorted(statlist, key=lambda x: int(x[1]))
I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be ...

5. Sort a list of tuples without case sensitivity    stackoverflow.com

How can I efficiently and easily sort a list of tuples without being sensitive to case? For example this:

[('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)]
Should look like this once sorted:
[('a', 5), ...

6. Python sort (list/tuple) in list    stackoverflow.com

I have some data either in list contains lists, or list contains tuples.

data = [[1,2,3], [4,5,6], [7,8,9]]
data = [(1,2,3), (4,5,6), (7,8,9)]
And I want to sort by the 2nd element in the ...

7. How to sort a list of inter-linked tuples?    stackoverflow.com

lst = [(u'course', u'session'), (u'instructor', u'session'), (u'session', u'trainee'), (u'person', u'trainee'), (u'person', u'instructor'), (u'course', u'instructor')]
I've above list of tuple, I need to sort it with following logic.... each tuple's 2nd element is dependent ...

8. sorting a list of tuples    stackoverflow.com

I have a list of tuples of the form (a,b,c,d) and I want to copy only those tuples with unique values of 'a' to a new list. I'm very new to ...

9. sort tuples in lists in python    stackoverflow.com

i was wondering if there was any simple way around sorting tuples in lists in python, for instance if i have a list:

list01 = ([a,b,c],[b,a,d],[d,e,c],[a,f,d])
and i sorted it, i would get:
([a,b,c],[a,b,d],[c,d,e],[a,d,f])?
or ...

10. Python: Sorting a tuple by date. Noob here    stackoverflow.com

Hey all. I would like to sort and return a section of a tuple with it sorted by date. I'd only like to sort the first to the 4th record (tuple[:3]) ...

11. Sorting bytes in words, tuples in python    stackoverflow.com

I looked around and I can't seem to find the proper way of sorting a 32 entry tuple by inverting every odd and even entry. ex:

1 0 3 2 5 4 ...

12. python tuple list sorting    stackoverflow.com

so I have a list with a whole bunch of tuples

j = 

[('jHKT', 'Dlwp Dfbd Gwlgfwqs (1kkk)', 53.0),
('jHKT', 'jbdbjf Bwvbly (1kk1)', 35.0),
('jHKT', 'Tfstzfy (2006)', 9.0),
('jHKT', 'fjznfnt Dwjbzn (1kk1)', 25.0),
('jHKT', 'Vznbsq sfnkz ...

13. Sorting Lists of tuples based on a list of tuples - Python    stackoverflow.com

I am trying to sort a list of tuples based on another list of tuples by a key in that list. Say I have the following:

list1 = [(5, 'something'),(2,'bobby'),(9,'suzy'),(6,'crab')]
list2 = [('something','othervalues'),('suzy','stuff'),('bobby','otherthings')]
And from ...

14. In python Sorting a list of tuples?    stackoverflow.com

How do you sort a list by elemant thats a tuple? Let say below is the list LL. I want to sort ID2 -- LL[1] which is a tuple as ...

15. Python dictionary to sorted tuples, can this be done better?    stackoverflow.com

I have an dictonary for my input with the following characteristics:

  • Each value will be either an integer, string or iterable (other than a string).
  • If the element is an iterable, each element ...

16. Sorting a dictionary of tuples in Python    stackoverflow.com

I know there's tonnes of questions on python sorting lists/dictionaries already, but I can't seem to find one which helps in my case, and i'm looking for the most efficient solution ...

17. what's the right way to put *arg in a tuple that can be sorted?    stackoverflow.com

I want a dict or tuple I can sort based on attributes of the objects I'm using as arguments for *arg. The way I've been trying to do it just ...

18. Sorting a list of tuples by specific columns?    python-forum.org

>>> import operator >>> wordfreq = [('grunted', 4), ('yelp', 1), ('tinkling', 1), ('lasted', 2), ('rule', 5), ('pictured', 1), ('extras', 1), ('elsie', 1), ('lives', 4), ('trims', 1), ('baked', 1)] >>> wordfreq.sort(key=operator.itemgetter(1)) >>> wordfreq [('yelp', 1), ('tinkling', 1), ('pictured', 1), ('extras', 1), ('elsie', 1), ('trims', 1), ('baked', 1), ('lasted', 2), ('grunted', 4), ('lives', 4), ('rule', 5)] >>>

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.