473,594 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('1 23456789')

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 1444

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('1 23456789')

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*********@gma il.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*********@gma il.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.or g> 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('1 23456789')


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
1276
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 win2k? any issues? anyone at all?
1
2084
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 when their product just cam out. I can't see why the tools shouldnt work with 2002 seeing as its almost identical to 2003. Has anyone heard anything
1
1478
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 datacenter and lost the installation in the process. I have the registration e-mail that was sent to them with the unlocking code so we just need the trial installation executable.
2
3687
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
2269
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 table? Does anyone has an example? Thanks, James
162
7171
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 (microsoft.com, cnn.com, etc.) at the W3 Validator; to my surprise none of them passed. Doesn't anyone care anymore, or are the standards more-or-less looked at as guidlines for web design?
0
1071
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. https://partner.microsoft.com/global/40016379 Has anyone in these groups had a chance to try them out? It sounds like it may be a good service but I'd like to hear from anyone who's
13
2215
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 are still using 97? 2000? I am slightly tempted to upgrade by a new client whose data is in 2000, but of course, I can just port it all back through Excel...right? and I guess I have seen a couple of nice features...
2
3898
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
2313
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 is called "Contoso", but I can't find it in the MSDN site, so I can evaluate it with the webcasts. If anyone know here is it, or if anyone is using it, please post here a
0
7941
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7874
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8246
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8231
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5404
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3895
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1205
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.