May-08-2022, 03:20 PM
(This post was last modified: May-08-2022, 03:20 PM by deanhystad.)
So what does your file look like? You've posted two very different formats.
I made a file that looks like this
data.txt
I made a file that looks like this
data.txt
Output:data= [
4 1 3 4 5
2 2 5
1 6
]
And processed it using this code.def bit_flags(bits, on=True, off=False): return [on if bit in bits else off for bit in range(1, max(bits)+1)] with open("data.txt", "r") as file: next(file) # Skip data[ for line in file: if len(line) > 1: # Skip ] numbers = list(map(int, line.split())) print(numbers, bit_flags(numbers[1:]))
Output:[4, 1, 3, 4, 5] [True, False, True, True, True]
[2, 2, 5] [False, True, False, False, True]
[1, 6] [False, False, False, False, False, True]