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 8703767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:56:25+00:00 2026-06-13T02:56:25+00:00

This is my script: from itertools import groupby import operator import csv l =

  • 0

This is my script:

from itertools import groupby
import operator
import csv

l = [['Cautus  B.V.', 'Cautus  B.V.plein 92', 'plein 92', '1129008', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa', 'admin@planet.nl'] ,
['Cautus  B.V.', 'Cautus  B.V.Wei 9-11', 'Wei 9-11', '1019123', '10', 'AVB', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa', 'admin@planet.nl'] ,
['Cautus  B.V.', 'Cautus  B.V.plein 92', 'plein 92', '1129008', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa', 'admin@planet.nl'] ,
['Cautus  B.V.', 'Cautus  B.V.Wei 9-11', 'Wei 9-11', '1019123', '10', 'BEDR', 'Geachte mevrouw Daa', 'Mevrouw C.P. Daa', 'admin.@planet.nl'] ,
['De company', 'De companytiellaan 42', 'tiellaan 42', 'KD0022232', '13', 'AVB', 'Geachte heer Tigch', 'De heer I. Tigch', 'imre@company.nl'] ,
['De company', 'De companytiellaan 42', 'tiellaan 42', 'KD0022232', '13', 'DAS', 'Geachte heer Tigch', 'De heer I. Tigch', 'imre@company.nl'] ,
['Slever ', 'Slever klopt 42', 'klopt 42', 'KD2220115', '17', 'AVB', 'Geachte heer Slever', 'De heer T. Slever', 'info@company.com']]

sortkey = operator.itemgetter(1,5)
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][:5]+v[0][5:]
   info_combine = map(operator.itemgetter(5),v)
   uniekid = k
   verz = info_combine
   naam = info_rest[0]
   risicoadr = info_rest[2]
   polisnummer = info_rest[3]
   relatienummer = info_rest[4]
   aanhef = info_rest[6]
   contactpersoon = info_rest[7]
   emailadr = info_rest[8]
   klantgegevens = [uniekid,naam,verz,risicoadr,polisnummer,relatienummer,aanhef,contactpersoon,emailadr,]

import csv
   with open('export.csv', 'w') as f:
       writer = csv.writer(f)
       writer.writerows(klantgegevens)

When i write i get this as a result in my .csv file:

S   l   e   v   e   r       k   l   o   p   t       4   2

As you can see he only writes one street name in it.

Anyone who can help me with this?

  • 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-13T02:56:26+00:00Added an answer on June 13, 2026 at 2:56 am

    You only have one list (you reset klantgegevens on each loop), and you write that list as if it is a full set of multiple rows.

    The CSV module sees that one list as a set of sequences, meaning that each string entry is seen as a sequence of individual characters, and that is what is then written to your csv file:

    >>> klantgegevens
    ['Slever klopt 42', 'Slever ', ['AVB'], 'klopt 42', 'KD2220115', '17', 'Geachte heer Slever', 'De heer T. Slever', 'info@company.com']
    >>> list(klantgegevens[0])
    ['S', 'l', 'e', 'v', 'e', 'r', ' ', 'k', 'l', 'o', 'p', 't', ' ', '4', '2']
    

    You can write each row separately while collecting the klantgegevens lists:

    import csv
    with open('export.csv', 'w') as f:
        writer = csv.writer(f)
        for k,v in l_final:
           info_rest = v[0][:5]+v[0][5:]
           info_combine = map(operator.itemgetter(5),v)
           uniekid = k
           verz = info_combine
           naam = info_rest[0]
           risicoadr = info_rest[2]
           polisnummer = info_rest[3]
           relatienummer = info_rest[4]
           aanhef = info_rest[6]
           contactpersoon = info_rest[7]
           emailadr = info_rest[8]
           klantgegevens = [uniekid,naam,verz,risicoadr,polisnummer,relatienummer,aanhef,contactpersoon,emailadr,]
           writer.writerow(klantgegevens)
    

    Now the list will be treated as a sequence of columns, writing each line as you complete it.

    Alternatively, you’d have to collect each klantgegevens list into a results list:

    results = []    
    for k,v in l_final:
        # processing
        klantgegevens = [uniekid,naam,verz,risicoadr,polisnummer,relatienummer,aanhef,contactpersoon,emailadr,]
        results.append(klantgegevens)
    

    Then write that list of lists to your CSV file:

    import csv
    with open('export.csv', 'w') as f:
        writer = csv.writer(f)
        writer.writerows(results)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from itertools import groupby #input l = [['Cautus B.V.', 'plein 92', '1129008', '10', 'AVB',
I took this script from here : import csv from itertools import izip f
I have copied this script from python web site : import sqlite3 import csv
I've been trying to make this script from ClearBox3 to stop conflicting with MooTools
So I call this PHP script from the command line: /usr/bin/php /var/www/bims/index.php projects/output and
I have this part of script from my GAE application which uses webapp2, which
I am using a script from this discussion: https://wordpress.stackexchange.com/a/14711/14649 It works great, but when
I'm trying to modify the code from this script . Basically I'm trying to
I tweaked this script that I used from JqueryUi and I have a problem.
I have this script that collects data from users and I want to check

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.