-1

I get keypress and timing output as tuples in a list of lists.

output = [[], [], [('m', 2.8167322647641413)], [], [('m', 2.8179350001591956)], [], [], [], [], [], [], [('m', 0.3381059524253942)], []]

I manage to select all the non-empty lists using:

for i in x:
    if i != []:
        print i

How do I also get the corresponding position in the output list? I tried:

for idx, val in enumerate(x):
    print(idx, val)

but that gives me all the indices and all lists.

1 Answers1

1

Test val if it is non-empty before printing:

for idx, val in enumerate(x):
    if val:
       print(idx, val)
Dan D.
  • 73,243
  • 15
  • 104
  • 123
  • 1
    When checking for non-emptiness for python list (or other containers), please use the expression `len(thing) == 0`, which is way more clear. – KokaKiwi Dec 08 '16 at 23:02