Solved

Looping problem - Python 3.4

Posted on 2014-11-27
2
155 Views
Last Modified: 2014-11-27
I am trying to create a two dimensional list (newlist) from a single dimensional list (Original).

Original =[6,12,45,23,8,32,99,100]

newlist =[[6, 12], [45, 23], [8, 32],[99,100]]  ..... desired result

newlist =[[6, 12], [45, 23], [8, 32]] ............ actual result

Looks like the looping stops before the end of the process.

I have attached the .PY file

Thanks in advance for any help.
testing.py
0
Comment
Question by:jameskane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 40469348
In general, it's rarely a good idea to change the control variable that you're iterating over.  Here's one way to get the results that you're after.  
while len(Original) != 0:
   newlist.append(Original[0:2])
   Original = Original[2:]

Open in new window

0
 

Author Closing Comment

by:jameskane
ID: 40469394
Perfect. AND I learned something important

Many thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python error - Need Help 12 123
Copy Files - Python 7 133
Modify a small python script 19 128
Python sort list of tuples, skipping column 2 61
The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question