Pythonのお勉強 Part6 ..
[2ch|▼Menu]
305:デフォルトの名無しさん
22/10/15 19:03:32.69 jl8SG5IY0.net
あんま綺麗じゃないけど、こんな感じでいいのか?
競プロの連中ならもっとスマートなの書いてくれるはず
text = "aaabbc"
char = "abcdefghijklmnopqrstuvwxyz"
char_dict = []
for c in char:
____count = 0
____for t in text:
________if c == t:
____________count += 1
____if count > 0:
________char_dict.append({"name":c, "count":count, "left":count})
char_dict = sorted(char_dict, key=lambda e: (e["left"], -e["count"]), reverse=True)
result = ""
pre = ""
for _ in text:
____ci = 0
____while True:
________now = char_dict[ci]["name"]
________if now == pre:
____________ci += 1
________else:
____________result += now
____________pre = now
____________char_dict[ci]["left"] -= 1
____________char_dict = sorted(char_dict, key=lambda e: (e["left"], -e["count"]), reverse=True)
____________break
print(result)


次ページ
続きを表示
1を表示
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

503日前に更新/241 KB
担当:undef