[過去ログ] Pythonのお勉強 Part68 (1002レス)
1-

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
325
(2): (ワッチョイ 0f02-9zfq) 2022/10/15(土)19:03 ID:jl8SG5IY0(1/4) AAS
あんま綺麗じゃないけど、こんな感じでいいのか?
競プロの連中ならもっとスマートなの書いてくれるはず

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-
あと 677 レスあります
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ

ぬこの手 ぬこTOP 0.030s