jeudi 5 juillet 2018

'int' object is not iterable while creating dictionary

I'm trying to create a dictionary in python. However, I want to create the dictionary using the random values. The desired output should be in the form {'a':1, 'b':2} in the format.

import numpy as np
import pandas as pd
import random
import string

value = np.random.random(10)
np.random.seed(42)
key = list(np.random.choice(list(string.ascii_lowercase), 10))
key, value

def map_values(key, value):
i = len(key)
j = len(value)
for i in len(key):
    print('key[i]' +'value[j]')
    i = i+1
    j = j+1
    return map_values()

map_values(key, value)

However while running the above code, I got the error 'int' object is not iterable. Can someone explain the reason for the error and rectify the code as I'm new to python and trying to learn it.




Aucun commentaire:

Enregistrer un commentaire