Sep-04-2018, 07:51 AM
Sep-04-2018, 07:56 AM
check
On second reading, can you elaborate what you mean exactly... i.e. in your example what is expected behaviour?
itertools.takewhile()
On second reading, can you elaborate what you mean exactly... i.e. in your example what is expected behaviour?
Sep-04-2018, 04:29 PM
So if I have
But if I have
li = ['A','B','A','C'] while 'A' in li: print(li.pop(0))It should print A B A C.
But if I have
li = ['A1','B','A2','C'] while 'A' in li: print(li.pop(0))Nothing prints. But what I want it to do is check if a substring of one of the elements contains 'A', such as in 'A1'.
Sep-04-2018, 05:49 PM
First of all, your first snippet will not print A B A C, but just A B A (each on separate line)
Next, you need to change second snippet to
Next, you need to change second snippet to
li = ['A1','B','A2','C'] while any('A' in item for item in li): print(li.pop(0))
Output:A1
B
A2
Finally, use collections.deque for memory efficient pop from either end.from collections import deque de = deque(['A1','B','A2','C']) while any('A' in item for item in de): print(de.popleft())
Sep-04-2018, 06:11 PM
Thanks, it works!