473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Can Anyone Help me on this

i m trying to reverse the order in which the
strings are stored in list

then pop it into another list

what m i doin worng??

here's the code:

list1 = []
list2 = []
list1.extend('123456789')

print list1

for a in list1:
list2 = list1.pop()

print list2
--
* Posted with NewsLeecher v3.0 Beta 7
* http://www.newsleecher.com/?usenet
Nov 3 '05 #1
9 1437

bl**@blah.blah wrote:
i m trying to reverse the order in which the
strings are stored in list

then pop it into another list

what m i doin worng??

here's the code:

list1 = []
list2 = []
list1.extend('123456789')

print list1

for a in list1:
list2 = list1.pop()

print list2
--
* Posted with NewsLeecher v3.0 Beta 7
* http://www.newsleecher.com/?usenet


well, mant things are happening, so many it's not clear to me what
you're trying to do...
BUT, considering your for statement, since you are poping elements out
of list you are shortening it, so you are only getting as far as
element '5'

If what you want is a reversed copy, you could just append list1
elements to list2, and use the reverse function such as
...
for i in list1: .... list2.append(i)
.... list2.reverse()
list1 ['1', '2', '3', '4', '5', '6', '7', '8', '9'] list2

['9', '8', '7', '6', '5', '4', '3', '2', '1']

Nov 3 '05 #2
Here is an example of copying then reversing a list:
l1 = [1,2,"C"]
l2 = l1[:]
l2.reverse()
l2

['C', 2, 1]
Nov 3 '05 #3
jm*********@gmail.com wrote:
If what you want is a reversed copy, you could just append list1
elements to list2, and use the reverse function such as
...
for i in list1: ... list2.append(i)
... list2.reverse()
list1 ['1', '2', '3', '4', '5', '6', '7', '8', '9'] list2 ['9', '8', '7', '6', '5', '4', '3', '2', '1']


It's much clearer and simpler to just do:
list2 = list1[:]
list2.reverse()

This saves all the messing around with append, and has the advantage
that it runs faster (by a factor of 30, on my computer).

-- David

Nov 3 '05 #4
jm*********@gmail.com writes:
If what you want is a reversed copy, you could just append list1
elements to list2, and use the reverse function such as
...
for i in list1: ... list2.append(i)
...


Don't do this by ahnd - let python do it for you:

list2 = list(list1)

or

list2 = list1[:]

<mike
list2.reverse()
list1 ['1', '2', '3', '4', '5', '6', '7', '8', '9'] list2

['9', '8', '7', '6', '5', '4', '3', '2', '1']


--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 3 '05 #5
....
list2=list1[:]
....
Yes, naturally, where was my head ?-))

Nov 3 '05 #6
bl**@blah.blah wrote:
i m trying to reverse the order in which the
strings are stored in list

then pop it into another list

what m i doin worng??

here's the code:

list1 = []
list2 = []
list1.extend('123456789')


How about this instead (Python 2.4 or later):

list2 = list(reversed('123456789'))

-Peter
Nov 3 '05 #7
Thanks Guys, Wow, i didnt knew that there was alist reverse function.
thx. also. i need a good documentation of the os and sys modules as
well as builtin functions of python.

the standard python documentation doesnt work for me. can u recommend
something?
--
* Posted with NewsLeecher v3.0 Beta 7
* http://www.newsleecher.com/?usenet
Nov 4 '05 #8
bl**@blah.blah <blahman> wrote:
Thanks Guys, Wow, i didnt knew that there was alist reverse function.
thx. also. i need a good documentation of the os and sys modules as
well as builtin functions of python.

the standard python documentation doesnt work for me. can u recommend
something?


I'm biased, but I'd recommend the book "Python in a Nutshell". My
suggestion: take advantage of the "Safari" online library for 2 weeks'
of free subscription -- make sure you cancel after 13 days if you want
to avoid being billed for the subscription's fee. In those 2 weeks you
get to read for free a few books in the online library -- I'd suggest
sampling the Nutshell, the Cookbook and possibly a couple more...
Alex
Nov 4 '05 #9
Thx Alex.
--
* Posted with NewsLeecher v3.0 Beta 7
* http://www.newsleecher.com/?usenet
Nov 4 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: asdf sdf | last post by:
i have an install issue with moinmoin on win2k. i've tried the mailing list, but it appears to be a very low traffic, low subscriber list. can i get a reality check? is anyone using moinmoin in...
1
by: Simon Harvey | last post by:
Hi chaps, Does anyone know if the beast is going to release Visual Tools for office to work with Visual Studio 2002 and not just 2003, or are they quite happy to shaft those that supported them...
1
by: Greg Steele | last post by:
Does anyone have a copy or know where I can get an installation executable for chiliReports 2.0 from chili! soft? The company I'm working for bought a copy several years ago, then moved their...
2
by: Ken Shaw | last post by:
G'day, I'm trying to tack down any delta compression library that I could licence for use in a project. Does anyone know of a decent binary delta compression library? cheers, Ken Shaw
0
by: james | last post by:
Hi guys! I´ve got a centerd table on my site with a black 1 pixel border. What i would like to do is to add a drop shadow to the table. Anyone know if it's possible to create a drop shadow for a...
162
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites...
0
by: Jay1969 | last post by:
Hey all, I heard there was a new service offered to Microsoft partners called ISV Advisory Services (see link) where MS is giving free dev consulting to their Partners. ...
13
by: penguin732901 | last post by:
Checking back for discussions, there was a lot of talk about 2000 being slower than 97, but not so much lately. What is the latest opinion? Anyone care to set up a poll for how many NG members...
2
by: Brent Taylor via AccessMonster.com | last post by:
HELP----DOES ANYONE HAVE A SIMPLE .mdb for MLM structure? Does anyone have an example database for multi-level marketing for a 3 Tier setup? Thank you, brenttaylor@actionimports.net
2
by: Bruno Alexandre | last post by:
Hi guys, does anyone know where is the Website used in the MSDN "Lear ASP.NET 2.0 with Jeff Prosise" (http://msdn.microsoft.com/asp.net/beta2/multimedia/default.aspx) events? The website used...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.