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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:23:40+00:00 2026-06-10T05:23:40+00:00

As a disclaimer, I am relatively new to programming, so please excuse any simple

  • 0

As a disclaimer, I am relatively new to programming, so please excuse any simple oversights I’ve made in writing this question.

I am using Python 2.7.3 and in doing so, have noticed something that seems unusual to me and haven’t been able to find a satisfactory explanation through Google Search or in the Python documentation. I can create a list and use zip() to create a list of tuples like so:

numList = range(4)
print zip(numList, numList)

[(0, 0), (1, 1), (2, 2), (3, 3)]

But when I use the iter() function on numList to create an iterable object and use zip() in a similar manner on this object, I get a much different result:

numList = range(4)
numList = iter(numList)
print zip(numList, numList)

[(0, 1), (2, 3)]

I would appreciate it if someone could explain the difference between the two procedures and what is going on behind the scenes that causes this to happen.

  • 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-10T05:23:41+00:00Added an answer on June 10, 2026 at 5:23 am

    In the first case you provide zip with “two” lists (really the same object i.e, list, but you provide two references to it), so it pulls out the same information from each list alternatingly and “zip”s it. Using the information does not consume it.

    In the second case, you create an iterator that would generate the values from 0 to 3 “on the fly”/on demand.

    You now provide this iterator twice to zip (again, the same reference to the iterator), which “pulls out” the data alternating from each iterator. (Ie it calls the iterator’s next() function).

    The “first” iterator provides the first value 0, the “second” iterator (really just a reference to the same one) provides the next value 1, and so on in alternating fashion until the iterator is exhausted at 3.

    So the main thing to keep in mind is that what you have provided to zip in both cases are two identical references to the same object. In the first case the list contains all the data already to be interleaved/zipped (accessing/using the data doesn’t make it unavailable). In the 2nd case, the data is being generated on demand, so the sequence generated is interleaved/zipped and as each value is generated, it is consumed and no longer available subsequently.

    I hope this makes some sense (be easier to sketch out on a piece of paper 🙂

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

Sidebar

Related Questions

Disclaimer: I am new to python and django but have Drupal programming experience. I'm
DISCLAIMER: I'm relatively new to Linux. I debated putting this on SuperUser or ServerFault
Disclaimer This is not strictly a programming question, but most programmers soon or later
Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer, Please pardon grammatical syntax. I'm using the simple linkedin php library that is
Disclaimer: I'm relatively new to iOS programming, and am trying to teach myself the
Disclaimer: I am very new to iOS development. Please excuse the possible stupidity of
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
Disclaimer: this question is driven by my personal curiosity more than an actual need
Disclaimer, new to programming, working my way through C++ Prime Plus 6th ed. I'm

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.