Make a dictionary in Python from input values

前端 未结 10 1370
情深已故
情深已故 2021-02-03 12:06

Seems simple, yet elusive, want to build a dict from input of [key,value] pairs separated by a space using just one Python statement. This is what I have so far:



        
10条回答
  •  别那么骄傲
    2021-02-03 12:49

    Take input from user:

    input = int(input("enter a n value:"))
    
    dict = {}
    
    for i in range(input):
    
        name = input() 
    
        values = int(input()) 
    
        dict[name] = values
    print(dict)
    

提交回复
热议问题