Skip to content

Commit 6146c4a

Browse files
committed
[BOJ] 4358 생태학 (S2)
1 parent 333a790 commit 6146c4a

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

심수연/5주차/260128.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
for i in input:
99
word = i.strip()
10+
if not word:
11+
continue
12+
1013
if word in dict:
1114
dict[word] += 1
1215
else:
@@ -17,15 +20,9 @@
1720

1821
# 조건: 사전순으로 출력하고, 그 종이 차지하는 비율을 백분율로 소수점 4째자리까지 반올림
1922

20-
# 사전순으로 출력
21-
# lambda word
22-
# 소문자로 바꿨을 때 min부터 나와야 함
23-
sorted_dict = sorted(dict, key=lambda word: word.lower())
24-
# ['Ash', 'Aspen', 'Basswood', 'Beech', 'Black Walnut', 'Cherry', 'Cottonwood', 'Cypress', 'Gum', 'Hackberry', 'Hard Maple', 'Hickory', 'Pecan', 'Poplan', 'Red Alder', 'Red Elm', 'Red Oak', 'Sassafras', 'Soft Maple', 'Sycamore', 'White Oak', 'Willow', 'Yellow Birch']
25-
2623
total = sum(dict.values())
2724

28-
for word in sorted_dict:
25+
for word in sorted(dict):
2926
ratio = dict[word] / total * 100
3027
print(f"{word} {ratio:.4f}") # 소수점 4째자리까지 반올림
3128

0 commit comments

Comments
 (0)