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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:25:17+00:00 2026-05-24T11:25:17+00:00

I am trying to write alternating elements of multiple lists to a file using

  • 0

I am trying to write alternating elements of multiple lists to a file using Python. I can write all of one list, and then all of another list, but am having difficulty doing it in an alternate order. My code looks like this:

foo = ['a', 'b', 'c']
bar = ['1', '2', '3']
fileout = open('zut.txt', 'w')
for i, el in foo, bar:
    fileout.write('%s\t%s' % (i, el))

However this produces a ValueError when I try and run it. For clarification, I am trying to produce a file like this:

a    1
b    2
c    3

Can anyone help me to achieve this? Thanks!

  • 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-24T11:25:18+00:00Added an answer on May 24, 2026 at 11:25 am

    You can use the following code:

    foo = ['a', 'b', 'c']
    bar = ['1', '2', '3']
    with open('zut.txt', 'w') as fileout:
        for x,y in zip(foo, bar):
            fileout.write('%s\t%s\n' % (x,y)) # you missed here '\n'
    

    Read more about ‘zip’ and use ‘with open…’ to be sure that file will be automatically closed

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

Sidebar

Related Questions

I'm trying to write a simple mail server using Python. I found smtpd that
Trying to write a couple of functions that will encrypt or decrypt a file
Im trying to write a single byte at a certain location in a file.
im trying to write an app that will display a list off lines from
I'm trying to write a simple web interface to allow users to install one
I've been trying to write a small library using Thor to help assist me
I was trying to write a regexp to replace all occurrences of \n with
Using Drupal 6.20. We can setup some form elements like this:- <input type=select name=somename[]><option>ohai</option></select>
I'm trying to write a method that merges a doubly linked list in an
I'm trying to use JAXB to pull some elements from a large XML file

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.