## 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
Solved

# Looping problem - Python 3.4

Posted on 2014-11-27
147 Views
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
Question by:jameskane

LVL 25

Accepted Solution

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:]
``````
0

Author Closing Comment

ID: 40469394
Perfect. AND I learned something important

Many thanks
0

## Featured Post

Question has a verified solution.

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

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…