We created dict={a:1,b:2,c:4,d:8} and list=[a,b] I want to make a list with the values of a and b as factors, ->[1,2] Like this What should I do?ㅜㅜ/
python
dict={"a":1, "b":2, "c":4, "d":8}
list= ["a","b"]
selected_values = [dict[a] for a in list]
print(selected_values)
Use the feature list compression.
© 2024 OneMinuteCode. All rights reserved.