Make a dictionary in Python from input values

前端 未结 10 1374
情深已故
情深已故 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 13:01

    for i in range(n):
        data = input().split(' ')
        d[data[0]] = data[1]
    for keys,values in d.items():
        print(keys)
        print(values)
    

提交回复
热议问题