On 2011/11/10 09:10 AM, lina wrote:
Hi,
How to remove the coming duplication,
Here I wrote one (not working):
a=['2', '5', '7', '5', '5']
for i in range(len(a)-1):
if a[i+1]==a[i]:
a.remove(a[i+1])
if i not in range(len(a)):
break
a
You have the error because the square brackets are missing. You should have
done this:
b=[b.append(a[i]) for i in range(len(a)) if a[i] != b[-1]]
This would however give you an index out of range error.
That said, may I ask what it is exactly you are trying to achieve?
Cheers.
Sent from my B
Hello,
list.remove will remove the first occurrence of the value from the list. So
the output is expected as far as Python is concerned.
May be you should think about using pop function.
Please take a look at the code below
>>> def RemoveComingDuplicates(a):
for i in range(len(a)-1):
print i,i+
Try this
>>> a=['2', '5', '7', '5', '5']
>>> d=list(set(a))
>>> d
['2','5','7']
Is there any reason why your numbers are in quotes???
Hope this helps.
Sent from my BlackBerry wireless device from MTN
-Original Message-
From: lina
Sender: tutor-bounces+delegbede=dudupay@python.or
Bad to reply to my own post.
Failed to understand the
>> just remove the coming duplication, not unique the list.
Sorry; ignore my ideas
Asokan Pichai
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.p
>>> for i in range(len(a)):
if i == 0:
b.append(a[i])
if a[i]!=b[-1]:
b.append(a[i])
This one seems work, but looks clumsy,
Thanks for any suggestions that helps to improve.
Best regards,
___
Tutor mailli
On Thu, Nov 10, 2011 at 12:40 PM, lina wrote:
> Hi,
>
> How to remove the coming duplication,
>
> Here I wrote one (not working):
>
>
> >>> a=['2', '5', '7', '5', '5']
> >>> for i in range(len(a)-1):
>if a[i+1]==a[i]:
>a.remove(a[i+1])
>if i not in range(len(a)):
>
b = []
b=b.append(a[i]) for i in range(len(a)) if a[i] != b[-1]
showed me:
SyntaxError: invalid syntax
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Hi,
How to remove the coming duplication,
Here I wrote one (not working):
>>> a=['2', '5', '7', '5', '5']
>>> for i in range(len(a)-1):
if a[i+1]==a[i]:
a.remove(a[i+1])
if i not in range(len(a)):
break
>>> a
['2', '7', '5', '5']
I wish
I am using python version 2.7.2. I put the version of livewires for python
2.x in the right folder this time and after running the following program I
got a different error message. Here they are.
program
# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
I installed livewires for python 2.x so should that work with python
version 2.7.2 ? I typed in the code you see below and got the following
error message.
Here is the code.
from livewires import games
and here is the error message
Traceback (most recent call last):
File "C:/Python27/new_grap
Thank you. I looked it up and http://www.python.org/dev/peps/pep-0008/ says the
following:
Class Names
Almost without exception, class names use the CapWords convention.
Classes for internal use have a leading underscore in addition.
Package and Module Names
Modules should hav
On Wed, Nov 9, 2011 at 6:26 AM, Albert-Jan Roskam wrote:
> Ah, good that they've renamed it to lowercase. Isn't there a convention
> to only use a capital for class names? (and of course for constants, which
> are all caps).
>
I think so, I know to adhere PEP 8 that is definitely required for na
Ah, good that they've renamed it to lowercase. Isn't there a convention to only
use a capital for class names? (and of course for constants, which are all
caps).
Cheers!!
Albert-Jan
~~
All right, but apart from the sanitation
14 matches
Mail list logo