+ 1

I want to change the values of dictionary by using range in List comprehension is this possible?

l = dict([(key,value) for key in range(1,7) for value in range(5,10)]). - -Output : {1: 9, 2: 9, 3: 9, 4: 9, 5: 9, 6: 9} want to change the value by using range.

2nd Feb 2022, 11:10 AM
Manoj Bhaagam
2 Respuestas
+ 2
Do you mean like this? d = dict([e for e in zip(range(1,7), range(5,11))]) Output: {1:5, 2:6, 3:7, 4:8, 5:9, 6:10}
2nd Feb 2022, 11:37 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
Ani Jona 🕊 Yes,thank you
2nd Feb 2022, 11:45 AM
Manoj Bhaagam