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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:46:45+00:00 2026-06-15T04:46:45+00:00

How would I make a dictionary that has keys that represent not just a

  • 0

How would I make a dictionary that has keys that represent not just a single string, but multiple strings (array)?
So each key is tied to an array that I can keep appending new strings to if the key is present in another file?

I am a relatively new Python programmer so I can visualize how my script would work… but alas I can’t think of the proper syntax.

I have the logic down (I think), I just need help with which modules or functions to use in Python. I am about 3/4 the way through Learn Python the Hard Way by Zed Shaw, if you need a reference to my current knowledge in Python.

Lets get to it. Example:

File 1:

A
B
C
D

File 2:

Ted A
Mike A
Wilma B
Frank C
Dog D
Fred D

File 3:

Jon Ted
Sid Ted
Mic Mike
Will Dog
Tod Dog

Hopeful Result (write to File 4):

>A Ted Mike Jon Sid Mic
>B Wilma
>C Frank
>D Dog Fred Will Tod

So using file 1 for the keys we can fill the elements with file 2 and 3 if the key is present. Notice in file 2 A and D have multiple answers. Next look into file 3 and we expand even further; we also see that Jon and Sid(file3) = Ted(file2) = A. A also = Mike (file2) = Mic (file 3)

This is the simplest example of my data (100,000’s of sequences), and the real kicker is I have five hierarchically expanding files, not just 2 (example above).

~~~ Answered ~~~

Thank you F.J and others

  • 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-15T04:46:46+00:00Added an answer on June 15, 2026 at 4:46 am

    The following should work:

    keys = []
    data = {}
    names = {}
    
    for line in open('file1', 'r'):
        keys.append(line.strip())
        data[line.strip()] = []
    
    for line in open('file2', 'r'):
        name, key = line.strip().split()
        if key in data:
            data[key].append(name)
            names[name] = key
    
    for line in open('file3', 'r'):
        nickname, name = line.strip().split()
        if name in names:
            data[names[name]].append(nickname)
    
    with open('file4', 'w') as file4:
        for key in keys:
            file4.write('>{0} {1}\n'.format(key, ' '.join(data[key])))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would i make it so that (this that - just examples) dont return
I want to make a WindowBaseClass that derives from Window but has a few
I am trying to make a Dictionary in C# that uses a boolean array
I have a javascript dictionary object which has a pre-set keys that are defaulted
How would I make this code smaller? Maybe a toggle, but people were saying
Possible Duplicate: C# dictionary type with unique keys and values I would like to
Now I know that just putting an array with 16 digits is too much
I would make to make a small WYSIWYG editor similar to the one used
It would make life so much easier!
i would make an application client server with java to change or modify the

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.