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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:39:45+00:00 2026-06-01T05:39:45+00:00

Beginner question: I have a dictionary where the values are lists of (a variable

  • 0

Beginner question:
I have a dictionary where the values are lists of (a variable # of) strings. Ultimately, I would like to write each dictionary entry to a single tab-delimited line with the key as column 1 and the individual items from the value list as columns 2-n. I have used the following code to generate an output file with the key as column 1 and the value list as column 2, but I’m not sure how to proceed from there.

mydict = {'spider':['kate', 'susan'],
          'fish':['kate'],
          'dog':['andy'], 
          'cat':['andy','colby','jeff']} 
f = open('outfile.txt', 'w') 
writer = csv.writer(f, delimiter = '\t')
for key, value in orfdict.iteritems():
    writer.writerow([orf] + [value])

The python documentation suggests that you can use zip() to create a list form key:value pairs, but when I try this at the interactive prompt:

>>> for key,value in mydict.iteritems():
...     mypair = zip(key,value)
...     print mypair

I get this strange output, so I obviously I’m not understanding things:

[('f', 'kate')]
[('c', 'andy'), ('a', 'colby'), ('t', 'jeff')]
[('s', 'kate'), ('p', 'susan')]
[('d', 'andy')]

Is the simplest way to do this going to be creating an empty list for each iteration over the dictionary, then appending to that list first the key, and then each of the values with an indented for loop? I feel like I must be missing something.

  • 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-01T05:39:46+00:00Added an answer on June 1, 2026 at 5:39 am

    Try this to add a single value to an existing list:

    writer.writerow([key] + value)
    

    (key is a single value, value is already a list)

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

Sidebar

Related Questions

I have a beginner question : I'd like to write a crawler (~1000 webpages)
Absolute beginner question: I have a template file index.html that looks like this: ...
A beginner question... I have a list like this: x <- c(aa=v12, bb=x21, cc=f35,
This seems like a pretty beginner question; however, I have no idea what the
Absolute beginner question here. I have two lists in mathematica. The first one was
This is kind of a beginner question. For now I have the implementation like
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Bit of a beginner question here: Say I have a block of xml: <root>
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
I'm new to Java and I have a beginner question: NumberFormat is an abstract

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.