0

I am trying to not print consecutive duplicates with a zip list but I am a little confused about the tuple structure here. If it were a simple list I would either use groupby or something simple like if y[i] != y[i-1] but this does not work here. I also can't seem to append it to a list which I tried... I am missing something in the details here.

and example input would be:

aa b aa aa b c

which would give me:

aa b aa b c

here is my code so far:

from __future__ import print_function
import sys

in_file = sys.argv[1]

with open(in_file) as f:
    do stuff not related to this question...

for x in zip(*lis):
    for y in x :
        if y[i] != y[i-1]:
            print(y+' ', end='')
    print('\n')

Sorry if this question is confusing, feel free to make any changes to help others :-)

cs95
  • 379,657
  • 97
  • 704
  • 746
badner
  • 768
  • 2
  • 10
  • 31

1 Answers1

1

try this,

from itertools import groupby
a = "aa b aa aa b c"
q = tuple(a.split()) #here q is tuple 
''.join([x for x,y in groupby(q)]) # use your tuple inside groupby
Mohideen bin Mohammed
  • 18,813
  • 10
  • 112
  • 118