How to multiply dictionary values by a number in Python

1 Answer

0 votes
dict = {'a': 4, 'b': 6, 'c': 2, 'd': 8, 'e': 3}

number = 3

dict.update((key, value * number) for key, value in dict.items())

print(dict)




'''
run:

{'a': 12, 'b': 18, 'c': 6, 'd': 24, 'e': 9}

'''

 



answered Jul 11, 2022 by avibootz

Related questions

3 answers 225 views
1 answer 132 views
1 answer 114 views
1 answer 169 views
...