modifying iterator value.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chun ping wang

    #1

    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!


  • Leif K-Brooks

    #2
    Re: modifying iterator value.

    chun ping wang wrote:[color=blue]
    > i want to modify an iterator value.
    >
    > for x in someList
    > x = 1[/color]

    for index, value in enumerate(someL ist):
    someList[index] = 1

    Comment

    • Thomas Nelson

      #3
      Re: modifying iterator value.

      There is also this way:

      for index in range(len(someL ist)):
      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

      Comment

      Working...