▷ 오늘 학습 내용: 자료구조 강의(1~2)
리스트 길이: 리스트에 저장된 아이템의 개수
students = ['홍길동', '박찬호', '박승철', '김지은']
#1
for i in range(len(students)):
print(students[i])
#2
n=0
while n < len(students):
print(students[n])
#3
for item in students:
print(item)
# 학급별로 학생 수 구하기
studentCnts = [[1,19], [2,20], [3,22], [4,18], [5,21]]
for i in range(len(studentCnts)):
print('{}학급 {}명'.format(studentCnts[i][0], studentCnts[i][1])
for classNo, cnt in studentCnts:
print('{}학급 {}명'.format(classNo, cnt))
# 과락 과목 구하기
minScore = 60
scores [['국어', 58], ['영어', 77], ['수학', 89]]
#1
for item in scores:
if item[1] < minScore:
print('과락 과목: {}, 점수: {}'.format(item[0], item[1]))
#2
for subject, score in scores:
if score < minScore:
print('과락 과목: {}, 점수: {}'.format(subject, score))
#3
for subject, score in scores:
if score >= minScore:
continue
print('과락 과목: {}, 점수: {}'.format(subject, score))
studentCnts = [[1,18], [2,19], [3,23], [4,21], [5,20]]
#1
n = 0
while n < len(studentCnts):
print(studentCnts[n])
n += 1
#2
n = 0; flag = True
while flag:
print(studentCnts[n])
n += 1
if n == len(studentCnts):
flag = False
#3
n = 0
while True:
print(studentCnts[n])
n += 1
if n == len(studentCnts[n]):
break
# 과락 과목 구하기
minScore = 60
scores [['국어', 58], ['영어', 77], ['수학', 89]]
#1
n=0
while n < len(scores):
if scores[n][1] < minScore:
print('과락: {}({}점)'.format(scores[n][0], scores[n][1]))
n+=1
#2
n=0
while n < len(scores):
if scores[n][1] >= minScore:
n+=1
continue
print('과락: {}({}점)'.format(scores[n][0], scores[n][1]))
n+=1
enumerate() 함수를 이용하여 아이템을 열거할 수 있다.
문자열에도 적용할 수 있다.
sports = ['농구', '축구', '야구', '배구']
for idx, value in enumerate(sports):
print('{} : {}'.format(idx, value))
# 문자열에 적용하기
str = '오늘 날씨가 좋습니다.'
for idx, value in enumerate(str):
print('{} : {}'.format(idx, value))
📝 파이썬 초급, 중급 강의를 들으면서 리스트, 딕셔너리 등 자료구조에 대해 궁금한 점이 많았는데 예전에 찾아본 내용보다 훨씬 더 많은 개념들이 있었다. 코드만 보고 이해하는거랑 직접 해보는거랑 다르다는 것을 또 느꼈고 강의 계속 듣다보면 이전꺼 복습 할 시간이 많이 없다😢
▷ 내일 학습 계획: 자료구조 강의(3~4)