Make a dictionary in Python from input values

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

    This is what we ended up using:

    n = 3
    d = dict(raw_input().split() for _ in range(n))
    print d
    

    Input:

    A1023 CRT
    A1029 Regulator
    A1030 Therm
    

    Output:

    {'A1023': 'CRT', 'A1029': 'Regulator', 'A1030': 'Therm'}
    

提交回复
热议问题