-3

I'm learning Python3. I can't solve a problem... Please help me. I could input 2 different strings(One is consisted with string another is consisted with float). I'd like to make a dictionary from 2 different lists. I made first one for key, another is for value.

input1 = list(map(str, input().split()))
input2 = list(map(float, input().split()))

# output = dict(zip(input1), (input2))
output = dict((input1, input2) for (input1[i], input2[i]) in range(0, len(input2)))
print(output)

Don't care too much that comment(#) I found a post may help my probelm from stack overflow. Create a dictionary with list comprehension in Python

I did my best but I coudn't solve this...(New one below # comment, It is what I tried to reading that post)

Thanks to read my question!

BPK
  • 15
  • 1
  • 8

1 Answers1

3

You can make a dict from list of tuples:

numbers = [1,2,3]
words = ['one', 'two', 'three']

dict(zip(numbers, words))

It's just a matter of switching places of numbers and words lists, and you have keys/values switched too.

Ilija
  • 1,556
  • 1
  • 9
  • 12