Group « List « 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 » List » Group 

1. Sorting and Grouping Nested Lists in Python    stackoverflow.com

I have the following data structure (a list of lists)

[
 ['4', '21', '1', '14', '2008-10-24 15:42:58'], 
 ['3', '22', '4', '2somename', '2008-10-24 15:22:03'], 
 ['5', '21', '3', '19', '2008-10-24 15:45:45'], 
 ...

2. Python script to list users and groups    stackoverflow.com

I'm attempting to code a script that outputs each user and their group on their own line like so:

user1 group1  
user2 group1  
user3 group2  
...  
user10 group6
etc. ...

3. How to make a list comprehension with the group() method in python?    stackoverflow.com

I'm trying to write a little script to clean my directories. In fact I have:

pattern = re.compile(format[i])
...
current_f.append(pattern.search(str(ls)))
and I want to use a list comprehension but when I try:
In [25]: [i for ...

4. Reading and Grouping a List of Data in Python    stackoverflow.com

I have been struggling with managing some data. I have data that I have turned into a list of lists each basic sublist has a structure like the following

<1x>begins
<2x>value-1
<3x>value-2
<4x>value-3
 some ...

5. Alternative way to split a list into groups of n    stackoverflow.com

Let's say I have a list of arbitrary length, L:

L = list(range(1000))
What is the best way to split that list into groups of n? This is the best structure that ...

6. Python: arguments for using itertools to split a list into groups    stackoverflow.com

This is a question about the relative merits of fast code that uses the standard library but is obscure (at least to me) versus a hand-rolled alternative. In this

7. put stockprices into groups when they are within 0.5% of each other    stackoverflow.com

Thanks for the answers, I have not used StackOverflow before so I was suprised by the number of answers and the speed of them - its fantastic. I have not been through ...

8. Can Python's list comprehensions (ideally) do the equivalent of 'count(*)...group by...' in SQL?    stackoverflow.com

I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count? (I've ...

9. Identify groups of continuous numbers in a list    stackoverflow.com

I'd like to identify groups of continuous numbers in a list, so that:

myfunc([2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 20])
returns:
[(2,5), (12,17), 20]
And was wondering what the best way ...

10. idiomatic way to take groups of n items from a list in Python?    stackoverflow.com

Given a list

A = [1 2 3 4 5 6]
Is there any idiomatic (Pythonic) way to iterate over it as though it were
B = [(1, 2) (3, 4) (5, 6)]
other than ...

11. Organizing a random list of objects in Python    stackoverflow.com

So I have a list that I want to convert to a list that contains a list for each group of objects. ie ['objA.attr1', 'objC', 'objA.attr55', 'objB.attr4'] would return [['objA.attr1', 'objA.attr55'], ['objC'], ...

12. How do I yield a pre-unpacked list?    stackoverflow.com

I have a list that is created within an itertools.groupby operation:

def yield_unpacked_list():
    for key, grp in itertools.groupby(something_to_groupby, key=lambda x: x[0]):
        subset_of_grp ...

13. Creating sublists    stackoverflow.com

The opposite of list flattening. Given a list and a length n return a list of sub lists of length n.

def sublist(lst, n):
    sub=[] ; result=[]
    ...

14. Python: partition list of names into equally sized sublists    stackoverflow.com

I have a list of names, e.g. ['Agrajag', 'Colin', 'Deep Thought', ... , 'Zaphod Beeblebrox', 'Zarquon']. Now I want to partition this list into approximately equally sized sublists, so that the ...

15. Python - dividing a list-of-lists to groups    stackoverflow.com

Consider the following simplified case:

lol = [['John','Polak',5,3,7,9],
       ['John','Polak',7,9,2,3],
       ['Mark','Eden' ,0,3,3,1],
       ['Mark','Eden' ,5,1,2,9]]
What would ...

16. Group list by values    stackoverflow.com

Let's say I have a list like this:

list = [["A",0], ["B",1], ["C",0], ["D",2], ["E",2]]
How can I most elegantly group this to get this list output in Python:
list = [["A", "C"], ["B"], ...

17. Grouping items in two lists    stackoverflow.com

Give these two lists:

I[2]: list1 = ['r1', 'r1', 'r1', 'r2', 'r2', 'r3']

I[3]: list2 = [1,2,3,1,2,1]
What is the Pythonic way to construct the following dictionary?
I[5]: mydict
O[5]: {'r1': {'n1': 1, 'n2': 2, 'n3': ...

18. Grouping Elements of Lists Within a List by Index    stackoverflow.com

I am trying to take a list of lists, and return a list of lists which contain each element at an index of the original list of lists. I know that ...

19. how to use python to produce a group of anagram with a given list    stackoverflow.com

for example :giving a list ['car','bed','stop','pots','arc','tops','z','z','rac','deb'] then with the function: produce [['arc', 'car', 'rac'], ['bed', 'deb'], ['pots', 'stop', 'tops'], ['z', 'z']]

20. How to make groups of five elements from the list?    stackoverflow.com

My GAE application receives several files in the upload (can be from 0 to N). I have there list in files_arguments list:

files_arguments = self.request.arguments()
I need to take first 5 elements, process ...

21. Python list of list from CSV files to create grouped bar chart    stackoverflow.com

I have several CSV files in this format, named n-data.csv where n is the number of threads:

elapsed,label
120,Step 01
260,Step 02
113,Step 03
100,Step 01
200,Step 02
103,Step 03
and I would like to get the average of ...

22. How can I group equivalent items together in a Python list?    stackoverflow.com

I have a list like

x = [2, 2, 1, 1, 1, 1, 1, 1]
I would like to put the repeated numbers together like
[[2,2],[1,1,1,1,1,1]] 

23. How to find all groups in a list in python?    stackoverflow.com

I have a list like this [0,0,1,1,1,0,0,0,1,1,0,0,1,1,1,1] and I want to group them and then find the length of each group.So the result will be like that :[[2,0],[3,1].....[4,1]].Any help is appreciated.Thanks. ...

24. Grouping lists within lists in Python 3    stackoverflow.com

I have a list of lists of strings like so:

List1 = [
          ['John', 'Doe'], 
        ...

25. Get index from a list where the key changes, groupby    stackoverflow.com

I have a list that looks like this:

myList = [1, 1, 1, 1, 2, 2, 2, 3, 3, 3]
What I want to do is record the index where the items in ...

26. Finding and grouping anagrams by Python    stackoverflow.com

input: ['abc', 'cab', 'cafe', 'face', 'goo']
output: [['abc', 'cab'], ['cafe', 'face'], ['goo']]
The problem is simple: it groups by anagrams. The order doesn't matter. Of course, I can do this by C++ (that's my ...

27. appending groups of numbers to lists    python-forum.org

Hello pythoners, I have a similar problem to one i posted a few weeks ago: I have a list of numbers, ie: [98, 75, 87, 90, 92, 81, 90, 98, 93, 86, 79, 91, 74] I need to append every group of numbers >=90 to separate lists. So my new lists would be: [98], [90, 92], [90, 98, 93], [91] It's ...

28. Grouping a List of Names    python-forum.org

Let's say I have a table. Column 1 is a list of people. Column 2 is the type. Column 3 is an arbitary number. Like this: Chris, A, 3 John, B, 3 Betty, A, 1 Steve, C, 6 Paula, B, 11 Tony, A, 4 What I want to do is rewrite the list and group the people by type, and display ...

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.