What is a better way to deal with unknown list structures in python? -


my python program receives midi data c library. data this:

[[[[240,0,1,116]]],[[[3,100,8,1]]],[[[107,247,0,0]]]] 

and include timestamps this:

[[[[240,0,1,116],26738]],[[[3,100,8,1],26738]],[[[107,247,0,0],26738]]] 

i need data in array of bytes, timestamp values discarded. code wrote is:

        def convertmidisysex(data):                 while isinstance(data[0][0], list):                 out = []                 index, value in enumerate(data):                     out = out+value                 data = out              out = array.array('b')             in range(len(data)):                 if isinstance(data[i], list):                     j in range(len(data[i])):                         out.append(data[i][j])                         if out[-1] == 247:  # 0xf7 marker end sysex message                             return out 

i can't feeling i'm doing hard way. there better approach this?

a cleaner way have now:

# entry below mixes timestamped , non-timestamped inputs entry = [[[[240,0,1,116]]],    [[[3,100,8,1]]],          [[[107,247,0,0]]],    [[[240,0,1,116],26738]],          [[[3,100,8,1],26738]],[[[107,247,0,0],26738]]]  data = array.array('b') sublist in entry:     item in sublist[0][0]:         data.append(item)         if item == 247:             break 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -