Vote count:
-1
In a Python 3 program I'm writing, I have to convert a list of strings containing binary into a list of decimal numbers, i.e:
binary_data = ['00100001', '00011100', '00001100', '01001100', '10001100', '11001101']
integer_data = [int(binary_data, 2) for i in binary_data]
However, I get the following error:
TypeError: list indices must be integers, not str
Should I use map() instead?
asked 1 min ago
1 Answer
Vote count:
1
You should be converting i into decimal:
integer_data = [int(i, 2) for i in binary_data]
binary_data is the list of numbers.
answered 33 secs ago
List comprehension from list of strings
Aucun commentaire:
Enregistrer un commentaire