Make a dictionary in Python from input values

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

    record = int(input("Enter the student record need to add :"))
    
    stud_data={}
    
    for i in range(0,record):
        Name = input("Enter the student name :").split()
        Age = input("Enter the {} age :".format(Name))
        Grade = input("Enter the {} grade :".format(Name)).split()
        Nam_key =  Name[0]
        Age_value = Age[0]
        Grade_value = Grade[0]
        stud_data[Nam_key] = {Age_value,Grade_value}
    
    print(stud_data)
    

提交回复
热议问题