[EMAIL PROTECTED] wrote:
> Tim Williams:
>
>>You could also use a list comprehension for your case
>>
>alist = [1 ,2 ,3]
>alist = [x for x in alist if x != 2]
>alist
>>
>>[1, 3]
>
>
> The list comprehension filtering is the simpler and often the best
> solution. For memory-conscious
Tim Williams:
> You could also use a list comprehension for your case
> >>> alist = [1 ,2 ,3]
> >>> alist = [x for x in alist if x != 2]
> >>> alist
> [1, 3]
The list comprehension filtering is the simpler and often the best
solution. For memory-conscious people this is another possible
(un-python
bayerj wrote:
> > I'm going to assume that it's supposed to work like this, but could
> > someone tell me the reasoning behind it? I.E. why is 3 skipped?
>
> Because:
>
> >>> alist[2]
> 3
>
> You are removing the third item, not the second.
This is incorrect.
You may need to remind yourself that
On 5 Sep 2006 16:05:36 -0700, bayerj <[EMAIL PROTECTED]> wrote:
> > I'm going to assume that it's supposed to work like this, but could
> > someone tell me the reasoning behind it? I.E. why is 3 skipped?
>
> Because:
>
> >>> alist[2]
> 3
>
> You are removing the third item, not the second.
>
Actu
> I'm going to assume that it's supposed to work like this, but could
> someone tell me the reasoning behind it? I.E. why is 3 skipped?
Because:
>>> alist[2]
3
You are removing the third item, not the second.
--
http://mail.python.org/mailman/listinfo/python-list
On 05/09/06, Gregory Piñero <[EMAIL PROTECTED]> wrote:
> On 9/5/06, Tim Williams <[EMAIL PROTECTED]> wrote:
> > > It does already, you just haven't grasped list fully yet :):)
> > >
> > > when you remove 2 from alist, the list becomes length 2, there is no
> > > longer a 3rd item in the list to i
On 9/5/06, Tim Williams <[EMAIL PROTECTED]> wrote:
> > It does already, you just haven't grasped list fully yet :):)
> >
> > when you remove 2 from alist, the list becomes length 2, there is no
> > longer a 3rd item in the list to iterate over.
> >
> > Try this
> >
> > > >>> alist=[1 ,2 ,3, 4]
>
On 05/09/06, Tim Williams <[EMAIL PROTECTED]> wrote:
> On 05/09/06, Gregory Piñero <[EMAIL PROTECTED]> wrote:> I'm going
> to assume that it's supposed to work like this, but could
> > someone tell me the reasoning behind it? I.E. why is 3 skipped?
> >
> > >>> alist=[1,2,3]
> > >>> for item in ali
On 05/09/06, Gregory Piñero <[EMAIL PROTECTED]> wrote:> I'm going
to assume that it's supposed to work like this, but could
> someone tell me the reasoning behind it? I.E. why is 3 skipped?
>
> >>> alist=[1,2,3]
> >>> for item in alist:
> print item
> if item==2:
>
I'm going to assume that it's supposed to work like this, but could
someone tell me the reasoning behind it? I.E. why is 3 skipped?
>>> alist=[1,2,3]
>>> for item in alist:
... print item
... if item==2:
... alist.remove(item)
...
1
2
>>>
Bonus Question:
Can we m
10 matches
Mail list logo