when have existing dictionary, want simultaneously assign value it.
example:
it's sample dictionary.
people_list = { "tom": none, "david": none, "traivs": none, } i want each of key:value pairs has same value.
this wanted result.
people_list = { "tom": "hello", "david": "hello", "traivs": "hello", } except loop-statement, solve it?
one line:
people_list.update(dict.fromkeys(people_list.keys(),"hello"))
Comments
Post a Comment