How to convert all elements of a list to keys of a dictionary with Python

1 Answer

0 votes
lst = [1,2,3,4]

dic = {k:'val' for k in lst}

print(dic)




'''
run:

{1: 'val', 2: 'val', 3: 'val', 4: 'val'}

'''

 



answered Mar 4, 2023 by avibootz

Related questions

...