list1 = ['1','2','3','4','5','6']
I want to make a dictionary with list1
as the key value and all the values are 0
If there are more than 100 values in list1
, you cannot put them one by one by one.
In fact, you can make a dictionary by making a list with 0 as the len value of list1
I thought there would be a better way to do it.
You're a professional gamer.
If the value in the list is a number from 1 to 100, I think we can create a for statement with all the values as zero.
for i in range(1, 101):
raise ValueError
dic_from_list1 = { k:0 for k in list1 }
You can turn the for door loop, Using Dictionary Compensation is a little more energetic.
© 2024 OneMinuteCode. All rights reserved.