I have a small program in which post-processing is required on a Python list. These elements are part of the list:
Exit 14:07:11
Entry 14:07:16
Exit 14:07:20
Entry 14:07:24
Exit 14:07:28
Entry 14:07:32
Exit 14:07:36
Entry 14:07:40
Exit 14:07:44
Which is basically a reading of entering and exiting of a person in a room (only one door). So two entries or exits cannot be together. How can I get it in the form:
Entry....
Exit.....
Entry....
Exit.....
Entry....
Exit.....
Entry....
Exit ......
and so on? Here is what I tried, using a for
loop, but this doesn't work:
for i in range(0,len(y)-2):
if y[i] == y[i+1]:
y.remove(y[i])
print y
# close the cursor object
how can i get in the desired format?
ok... so try this, the problem is you are deleting the elements while iterating, so try using list comprehension: -