An example:
example = [None, b'1', b'2', b'3', b'4', b'1', None, None, b'8', b'56', b'66', b'77', b'1', None]
I need to change values in this list in the following way: bytes should be converted to int, None to 0 and every 6th and 7th element to a bool. The expected output:
expected_output = [0, 1, 2, 3, 4, True, False, 0, 8, 56, 66, 77, True, False]
My attempt:
[int(value) if value else bool(value) if index in (5,6) else 0 for index, value in enumerate(example)]
The result:
[0, 1, 2, 3, 4, True, False, 0, 8, 56, 66, 77, 0, 0]
I know there is a problem in this part of my code:
[int(value) if value else bool(value) if index in (5,6) else 0 for index, value in enumerate(example)]
^
|
|
How can I change every 6th and 7th element to a bool?