Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jennyonjourney/8b62f962981da4cae43220fa63ad7c51 to your computer and use it in GitHub Desktop.
Save jennyonjourney/8b62f962981da4cae43220fa63ad7c51 to your computer and use it in GitHub Desktop.
Python - hit pratice1
hit = [22,24,25,27,21,22,23,25,27,22,24,27,22]
hh = {}
# i번째가 아니라 hit의 'i'key라는 의미
# hh[i]는 hh의 딕셔너리의 i key라는 의미
# cnt 1 인상태인데 만약 i가 hh안에 있으면 cnt더하세요, 카운트 수가 올라가겠지.
for i in hit:
cnt = 1
if i in hh:
cnt += hh[i]
hh[i] = cnt
print(hh)
print(hh)
for i in hh:
print(i, ":", hh[i])
print('------------------------')
hit = ['h2','a4','a5','h7','h1','a2','a3','a5', 'h7','h2','h4','a7','h2']
#home팀/away팀으로 나누어 선수별 안타갯수를 정리하세요
#선수등번호 순서대로 출력, 안타갯수는 '*'의 갯수로 표현
print('-------선생님 답변---------')
home = {}
away = {}
#print(hit[1])
for x in hit:
team = away
if x[0]=='h':
team = home
cnt = 1
if x[1] in team:
cnt+=team[x[1]]
print(x, "->", x[0] + "," + x[1], ",", x[1] in team,",",cnt)
team[x[1]] = cnt
print(away)
print(home)
kk = list(away.keys())
kk.sort()
for i in kk:
print(i,":", away[i]*'*')
print('---------------------')
print('--------내답변--------')
home2 = {}
away2 = {}
for x in hit:
cnt = 1
if x[0] == 'h':
home2[x[1]]=cnt
cnt+=home2[x[1]]
print(x[0], ",", x[1])
for y in hit:
if y[0] == 'a':
away2[y[1]] = cnt
cnt+=away2[y[1]]
print(y[0],",",y[1])
print(home2)
print(away2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment