Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:52:34+00:00 2026-06-12T23:52:34+00:00

from itertools import groupby #input l = [[‘Cautus B.V.’, ‘plein 92’, ‘1129008’, ’10’, ‘AVB’,

  • 0
from itertools import groupby
#input
l = [['Cautus  B.V.', 'plein 92', '1129008', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['Cautus  B.V.', 'Wei 9-11', '1019123', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['Cautus  B.V.', 'plein 92', '1129008', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['Cautus  B.V.', 'Wei 9-11', '1019123', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
['De company', 'tiellaan 42', 'KD0022232', '13', 'AVB', 'Geachte heer Tigch', 'De heer I. Tigch'] ,
['De company', 'tiellaan 42', 'KD0022232', '13', 'DAS', 'Geachte heer Tigch', 'De heer I. Tigch'] ,
['Slever ', 'klopt 42', 'KD2220115', '17', 'AVB', 'Geachte heer Slever', 'De heer T. Slever']]
#script
l_clean = sorted(zip(zip(*l)[1], zip(*l)[4],))

l_final = [(k, zip(*v)[1]) for k,v in groupby(l_clean, key = lambda x:x[0])]

for k,v in l_final:

     print k,list(v)

#My output is:

Wei 9-11 ['AVB', 'BEDR']

klopt 42 ['AVB']

plein 92 ['AVB', 'BEDR']

tiellaan 42 ['AVB', 'DAS']

Problem

My problem is that i can’t seem to add the other data to the output the data i also want to have in the output is:

['Cautus  B.V.','1019123', '10', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'](not only for this entry but for all entry's)

I tryed everything changing/adding the key etc but it doesn’t seem to work.
I know my english is vague so if i need to clarify some words or anything just say so.
Already thx in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:52:35+00:00Added an answer on June 12, 2026 at 11:52 pm

    I’m having a difficult time understanding what you’re trying to do, but perhaps this will help:

    from itertools import groupby
    import operator
    #input
    l = [['Cautus  B.V.', 'plein 92', '1129008', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
    ['Cautus  B.V.', 'Wei 9-11', '1019123', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
    ['Cautus  B.V.', 'plein 92', '1129008', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
    ['Cautus  B.V.', 'Wei 9-11', '1019123', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa'] ,
    ['De company', 'tiellaan 42', 'KD0022232', '13', 'AVB', 'Geachte heer Tigch', 'De heer I. Tigch'] ,
    ['De company', 'tiellaan 42', 'KD0022232', '13', 'DAS', 'Geachte heer Tigch', 'De heer I. Tigch'] ,
    ['Slever ', 'klopt 42', 'KD2220115', '17', 'AVB', 'Geachte heer Slever', 'De heer T. Slever']]
    #script
    sortkey = operator.itemgetter(1,4)
    l_clean = sorted(l,key=sortkey)
    
    l_final = [(k, list(v)) for k,v in groupby(l_clean, key = operator.itemgetter(1))]
    
    for k,v in l_final:
       info_rest = v[0][:4]+v[0][5:]
       info_combine = map(operator.itemgetter(4),v) 
       print k,info_combine,info_rest
    

    Basically, I sorted all of the data based on a specific key. This way you don’t lose any data during the sort stage. I then changed the key in groupby to be consistent with the new data layout and printed the results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is an example use case of itertools.groupby() in Python: from itertools import groupby
This is my script: from itertools import groupby import operator import csv l =
from operator import itemgetter from itertools import takewhile xs = [ ('foo',1), ('bar',1), ('baz',2)
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
I took this script from here : import csv from itertools import izip f
I was doing a foolish thing like: from itertools import * rows = combinations(range(0,
Suppose I have this Python code: from itertools import count, tee original = count()
I'm creating a list with itertools from a list of ranges, so far I
from fabric.api import sudo, put, run def install(): run('source /home/user/.virtualenvs/demo/bin/activate') run('pip install requests') if
I am using Windows 7 64 bit. I have these imports from scikits.audiolab import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.