Howard k
Howard k

Reputation: 13

I have Multiple keys in the dictionary want to point to the same value what can I do

I am new to Python,so I hope someone can help me,Thx!

The program

dict=(zip((3,4,5),('Spring','Spring','Spring')))

why can't I cut the Program like..

dict=(zip((3,4,5),('Spring')))

I have Multiple keys in the dictionary want to point to the same value what can I do...

Upvotes: 1

Views: 53

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375744

Dict has a fromkeys class method that does just what you want:

>>> dict.fromkeys((3, 4, 5), "Spring")
{3: 'Spring', 4: 'Spring', 5: 'Spring'}

Upvotes: 3

Related Questions