info = ['20200000chulsookim', '20201111youngheelee', '20202222hakgunpark']
temp={}
student=[]
for i in range(len(info)):
for j in range(len(info[i])):
if info[i][j].isalpha()==True:
temp['id']=info[i][:j]
temp['name']=info[i][j:]
student.append(temp)
temp={}
break
print(student)
학번이랑 이름 붙어있는 어떤 정보들의 리스트에서
학번이랑 이름 분리해서 출력하는데
[{'id': '20201234', 'name': 'chulsookim'}] 이런 형식으로 출력해야 됨
문자열에서 숫자랑 문자 구분되는 지점 찾아서
딕셔너리에 key값으로 'id'랑 'name' 달아서
그 딕셔너리를, 최종적으로 출력한 리스트에 집어넣는데
코드 밑에서 네번째 줄인 temp={}
이거 안 넣으면
출력될 때 마지막 정보의 값으로 통일되버리는데
그 이유가 뭐임?
댓글 0