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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:28:00+00:00 2026-06-10T12:28:00+00:00

So I have file that with multiple line that look like this (space delimiter

  • 0

So I have file that with multiple line that look like this (space delimiter file):

A1BG      P04217     VAR_018369  p.His52Arg     Polymorphism  rs893184    -
A1BG      P04217     VAR_018370  p.His395Arg    Polymorphism  rs2241788   -
AAAS      Q9NRG9     VAR_012804  p.Gln15Lys     Disease       -           Achalasia

How do I make dictionary to look for id in second column and store the number (between words) on fourth column.

I tried this but it give me index of out range

lookup = defaultdict(list)
with open ('humsavar.txt', 'r') as humsavarTxt:
    for line in csv.reader(humsavarTxt):
        code = re.match('[a-z](\d+)[a-z]', line[1], re.I)
        if code: 
            lookup[line[-2]].append(code.group(1))

print lookup['P04217']
  • 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-10T12:28:02+00:00Added an answer on June 10, 2026 at 12:28 pm

    Here’s a variant of the original code:

    import csv, re
    from collections import defaultdict
    
    lookup = defaultdict(list)
    with open('humsavar.txt', 'rb') as humsavarTxt:
        reader = csv.reader(humsavarTxt, delimiter=" ", skipinitialspace=True)
        for line in reader:
            code = re.search(r'(\d+)', line[3])
            lookup[line[1]].append(int(code.group(1)))
    

    which produces

    >>> lookup
    defaultdict(<type 'list'>, {'P04217': [52, 395], 'Q9NRG9': [15]})
    >>> lookup['P04217']
    [52, 395]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge text file that I would like to split into multiple
I have multiple lines of texts in a text file that look similar to
I have a string that contains multiple parameters delimited by #, like this :
I need to extract requests from a log file that look like this :
I have multiple (8) WAR files and 1 EAR file that I want to
I have a File that COntains Strings in This Format: ACHMU)][2:s,161,(ACH Payment Sys Menus
I have a file that contains this <!-- CordovaVersion --> I want to replace
I have a file that looks like: 1 1 C C 1.9873 2.347 3.88776
I have a file that can be any thing like ZIP, RAR, txt, CSV,
I have a file that looks like: SECTION1 id name sub section1 sub section2

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.