PythonでThe Common Words
コード2
def checkio(first,second): f = set(first.split(",")) s = set(second.split(",")) common = f.intersection(s) print ",".join(sorted(common))
コード1
def checkio(first,second): f=first.split(",") s=second.split(",") n=[] for i in f: for j in s: if str(i) == str(j): n.append(i) if n != []: x = ",".join(sorted(n)) print x else: print ""
参考にしたサイト
- 「python join」 「文字列の分割・結合 split, join」
- 「python sord」 「ソート HOW TO」
- 「intersection python」 「3.7 set(集合)型 -- set, frozenset」
一言
setは集合計算をしたいときに使う