Created
May 22, 2021 21:44
-
-
Save x1001000/d028c71462dcc7603284f8557009d3f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 開檔,每一行的每一個字存入words | |
words = [] | |
with open(input()) as f: | |
for line in f.readlines(): | |
words += line.split() | |
# 若用words.append()方法 | |
# 會將line.split()傳出的串列 | |
# 當成一個東西加到words最後一項 | |
# 一一比對words中的每一個word長度是否為n | |
# 若為n則加入match_words集合 | |
n = int(input()) | |
match_words = set() | |
for word in words: | |
if words.count(word) == n: | |
match_words.add(word) | |
# sorted(match_words)是排序過的match_words | |
# 若match_words中的元素是字串 | |
# 則用字串的第一個字元的編碼排序 | |
# 預設為由小至大 | |
for match_word in sorted(match_words): | |
print(match_word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment