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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:09:59+00:00 2026-05-26T12:09:59+00:00

I am new to Python, and I am currently stumped by this problem: I

  • 0

I am new to Python, and I am currently stumped by this problem:

I have a list of dictionaries generated csv.DictReader. I have created the list with the function as follows:

def csvToDictList(filename):
    reader = csv.DictReader(open(filename, 'rb'))

    list = []
    for row in reader:
        list.append(row)

    return (list, reader.fieldnames)

This worked great, but CSV file I am processing has duplicate columns, so I end up with a dictionary like:

[
{'Column1': 'Value1', 'Column2': 'Value2', ... <some unique columns and values> ..., 'Column1': 'Value1', 'Column2': 'Value2'},
...
{'Column1': 'Value1N', 'Column2': 'Value2N', ... <some unique columns and values> ..., 'Column1': 'Value1N', 'Column2': 'Value2N'}
]

My main question is how do I remove duplicate columns out of this dictionary list?

I thought about iterating over each key, and then removing the column when I detect a duplicate key name with something like this:

def removeColumn(dictList, colName):
    for row in dictList:
        del row[colName]

But, won’t that remove both columns? Should I be operating on the hash-keys of the dictionary? Any help is appreciated!

EDIT : The duplicates I was seeing were actually present in the reader.fieldnames list. So, I was assuming the dictionaries contained these columns as well, which was an incorrect assumption.

  • 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-05-26T12:09:59+00:00Added an answer on May 26, 2026 at 12:09 pm

    There is nothing like duplicate keys in a dictionary.

    If you have more columns with the same name, DictReader will take only the last one (overwriting the previous ones).

    For the following CSV file:

    a,b,c,a,b
    1,2,3,4,5
    6,7,8,9,10
    

    the DictReader will return following dicts:

    {'a': '4', 'c': '3', 'b': '5'}
    {'a': '9', 'c': '8', 'b': '10'}
    

    thus throwing the previous values for a and b columns away.

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

Sidebar

Related Questions

I'm very new to Python and have a question. Currently I'm using this to
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
I am new to Python and currently have to write a python program/script to
I'm quite new to Python and currently I need to have a __repr__ for
I'm currently launching a programme using subprocess.Popen(cmd, shell=TRUE) I'm fairly new to Python, but
I'm really new to C -> Python interaction and am currently writing a small
Im new two python and am trying to grow a dictionary of dictionaries. I
I am really new to Python and I have been looking for an example
I am new to Python and this is my first time asking a stackOverflow
I am new to Python and currently am doing some translations from 2.7 to

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.