I'd appreciate your help writing better code.
I have a list of ~1000 values:
list_of_values = [0x123D, 0x844F, 0x33E9, ....., 0xFFFF, 0xFFFF, 0xFFFF]
The last values in the list will always be 0xFFFF, but I don't know how many exactly.
What I want is to get rid of all those trailing 0xFFFF values to shorthen the list.
I have a solution which works, but I feel isn't quite Pythonic enough:
list_of_values.reverse() # Start at the end of the list for index, value in enumerate(list_of_values): if value != 0xFFFF: # The first useable value list_of_values = list_of_values[index:] list_of_values.reverse() # Retun list ordering (or use [::-1] in previous line) break
This code works well, but can it be done better? I was thinking about using the any() function, but I haven't found a way to break and get the index using it.
Thanks again for your help :-)