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

  • Home
  • SEARCH
  • 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 8982125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:30:31+00:00 2026-06-15T20:30:31+00:00

I have read a cvs file and I would like to create a dictionary

  • 0

I have read a cvs file and I would like to create a dictionary from the information I have on that file. I´ve tried to use class csv.DictReader to that propose but it didnt gave me the results i wanted.

Now i am reading the file like this:

size_reader = csv.reader(f,dialect='excel-tab')

and I have as result this:

['chr1', '249250621']
['chr2', '243199373']
['chr3', '198022430']
['chr4', '191154276']
['chr5', '180915260']

I would like to make a dictionary with this structure:

dict ['chr4'] = 191154276
dict ['chr5'] = 180915260
dict ['chr2'] = 243199373

I tried regular expressions to split the elements the lines on the file but I had no success with it, maybe i used the wrong characters in the split function. Could you give some suggestion of how to separate the elements and built the dictionary?

  • 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-15T20:30:32+00:00Added an answer on June 15, 2026 at 8:30 pm

    Just convert it to a dict directly:

     result = dict(size_reader)
    

    This takes each two-column result from your size_reader CVS reader and uses that as the key and value for a python dictionary.

    To convert each value to integers, you’d need to use a dict comprehension to process each value:

    result = {k: int(v) for k, v in size_reader}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file like 120 column by 4500 row. I read the
I have this code to read a CVS file. It reads each line, devides
I have a really strange error. PHP can't read a file that do exists...
I have read tutorials and several stack overflow posts that suggest I should use
I have read from the internet that unless you work with old version sql
I have read that GLSL (specifically v1.0.17: my application is running under WebGL) compilers
I have read numerous people with this question and have tried numerous strategies. However,
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read that using database keys in a URL is a bad thing
I have some data in CSV like: Timestamp, Count 2009-07-20 16:30:45, 10 2009-07-20 16:30:45,

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.