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:
d={}
n = 3
d = [ map(str,raw_input().split()) for x in range(n)]
print d
Input:
A1023 CRT
A1029 Regulator
A1030 Therm
Desired Output:
{'A1023': 'CRT', 'A1029': 'Regulator', 'A1030': 'Therm'}
I have taken an empty dictionary as f and updated the values in f as name,password or balance are keys.
INPUT:
NOTE: I have added an extra line for each input for getting each input on individual lines on this site. As placing without an extra line creates a single line.
OUTPUT:
using
str.splitines()
andstr.split()
:This is what we ended up using:
Input:
Output: