+ 1

Dictionary

How to make each value of the list become a key for some dictionary values if I do not know how many values are in the dictionary

25th Oct 2022, 8:56 PM
Александр Ковяров
Александр Ковяров - avatar
5 Antworten
+ 6
You could use a for-loop to iterate over the list. On each iteration, add the element as key to the dictionary. Mind that lists can contain duplicate values and that keys must be unique.
25th Oct 2022, 9:27 PM
Lisa
Lisa - avatar
+ 6
aАлександр Ковяров , can you please provide: > a sample of the input list and a sample of the expected output. > your code attempt as a link to your code in playground
26th Oct 2022, 2:11 PM
Lothar
Lothar - avatar
+ 5
Ratnapal Shende , please do not post a ready-made code here as long as the op has not shown his attempt here. it does not really help to improve the coding skills of the op, better to give hints or tips.
26th Oct 2022, 2:14 PM
Lothar
Lothar - avatar
+ 1
Lothar sure
26th Oct 2022, 3:46 PM
Ratnapal Shende
Ratnapal Shende - avatar
0
Dictionary comprehension or zip or dict.fromkeys() Careful: Dictionary key are unique,
26th Oct 2022, 5:09 PM
Ashok314
Ashok314 - avatar