469,927 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

modifying iterator value.

Hi, I have something simple i want to do.

i want to modify an iterator value.

for x in someList
x = 1

is it possible to do that..if not how do i modify a list using iteration.

__________________________________________________ _______________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/g...ave/direct/01/

Apr 26 '06 #1
2 1429
chun ping wang wrote:
i want to modify an iterator value.

for x in someList
x = 1


for index, value in enumerate(someList):
someList[index] = 1
Apr 26 '06 #2
There is also this way:

for index in range(len(someList)):
someList[index] = 1

This is not as pretty or concise as enumerate(), but if you've never
seen that function before this may be more clear. I assume you're
familiar with the way range and len work.

THN

Apr 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.