updown_img = ['▲','▼']
a_list = ['1', '1', '1', '0', '0', '1', '1', '1', '0', '0']
There are two lists I'd like to change it to ▲ if it's 1 or ▼ if it's 0.
Desired output value
b_list = ['▲', '▲', '▲', '▼', '▼', '▲', '▲', '▲', '▼', '▼']
What should I do? I ask for your help me
python
using map, lambda
b_list = map(lambda x: updown_img[int(x)^1], a_list)
using list comprehension
b_list = [updown_img[int(x)^1] for x in a_list]
© 2024 OneMinuteCode. All rights reserved.