Too complicated. I think @JeromeJ's solution is cleaner. But:
a=('What', 'happened', 'then', '?', 'What', 'would', 'you', 'like', 'to', 'drink','?') start = 0 try: end = a.index('?', start)+1 except: end = 0 while a[start:end]: for i,j in enumerate(a[start:end]): print i,j start = end try: end = a.index('?', start)+1 except: end = 0
source share