Skip to content
Advertisement

Make dictionary from multiple list

I have a list of customers, and I want to generate a list of random numbers between 1 to 4 for each customer. I used the code below:

JavaScript

but I want to have a dictionary like:

JavaScript

How would I go about doing this in python?

Advertisement

Answer

Slight modifications to your existing loop is all you need. You can use your existing k to assign a new dictionary key & value:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement