-1

I have array

a = ['A','A','B']

I want to map 'A' to 1 and 'B' to zero. How can I do that?

rdas
  • 20,604
  • 6
  • 33
  • 46
Kushagra
  • 61
  • 2
  • 11
  • Does this answer your question? [Python: Convert list to dictionary with indexes](https://stackoverflow.com/questions/36459969/python-convert-list-to-dictionary-with-indexes) – Stevy Jun 06 '20 at 16:02

2 Answers2

1
[1 if c == 'A' else 0 for c in a]

?

bipll
  • 11,747
  • 1
  • 18
  • 32
0

If you want to do data mapping:

data = {'A':1, 'B': 0}
print(data['A'])
Out:
1