I was so miffed at not reading the OP's
mail carefully that I wrote a one liner.
Ok. Here it goes:
def no_adjacent_dup(lst):
return [ x for x, y in zip(lst, lst[1:]) if x != y] + [lst[-1]]
:-) Enjoyed working that one out; but whether it is a good solution
Asokan Pichai
snip
Thanks for all, I found the problems I faced is more tricky than the
simple list I gave.
Here the list is: a row of numbers, not one number,
such as print a_list[1] is:
1
1
9
7
7
9
9
9
print(a_list) is:
617
617
790
571
571
790
790
790
I attached the codes written based on the
Christian Witts wrote:
def remove_coming_duplication(a_list):
return [element for idx, element in enumerate(a_list) if element !=
a_list[idx-1]]
Beware of negative indices:
remove_coming_duplication([1, 2, 1])
[2, 1] # should be [1, 2, 1]
Asokan Pichai wrote:
On Thu, Nov 10, 2011 at 2:07 PM, Peter Otten __pete...@web.de wrote:
Christian Witts wrote:
def remove_coming_duplication(a_list):
return [element for idx, element in enumerate(a_list) if element
!=
a_list[idx-1]]
Beware of negative indices:
On 2011-11-10 09:26, lina wrote:
atoms=[]
def fetchonefiledata(infilename):
for line in open(infilename,r):
parts=line.strip().split()
atoms=parts[2]
print(atoms[0])
First you define atoms as an empty list, but in the line
atoms =
lina wrote:
Hi,
How to remove the coming duplication,
Here I wrote one (not working):
a=['2', '5', '7', '5', '5']
[...]
I wish to get a is [2,5,7,5]
just remove the coming duplication, not unique the list.
a = [2, 5, 7, 5, 5]
b = a[0:1] # slice of the first item only
for x in a[1:]:
On Thu, Nov 10, 2011 at 8:48 PM, Steven D'Aprano st...@pearwood.info wrote:
lina wrote:
Hi,
How to remove the coming duplication,
Here I wrote one (not working):
a=['2', '5', '7', '5', '5']
[...]
I wish to get a is [2,5,7,5]
just remove the coming duplication, not unique the list.
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 to get
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
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 maillist
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:
=dudupay@python.org
Date: Thu, 10 Nov 2011 15:10:57
To: tutorTutor@python.org
Subject: [Tutor] how to remove the coming duplication
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
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+1
BlackBerry wireless device from MTN
-Original Message-
From: lina lina.lastn...@gmail.com
Sender: tutor-bounces+delegbede=dudupay@python.org
Date: Thu, 10 Nov 2011 15:20:49
To: tutorTutor@python.org
Subject: Re: [Tutor] how to remove the coming duplication
b = []
b=b.append(a[i
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
15 matches
Mail list logo