[過去ログ]
Pythonのお勉強 Part68 (1002レス)
Pythonのお勉強 Part68 http://mevius.5ch.net/test/read.cgi/tech/1663235546/
上
下
前
次
1-
新
通常表示
512バイト分割
レス栞
このスレッドは過去ログ倉庫に格納されています。
次スレ検索
歴削→次スレ
栞削→次スレ
過去ログメニュー
325: デフォルトの名無しさん (ワッチョイ 0f02-9zfq) [sage] 2022/10/15(土) 19:03:32.69 ID:jl8SG5IY0 あんま綺麗じゃないけど、こんな感じでいいのか? 競プロの連中ならもっとスマートなの書いてくれるはず 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) http://mevius.5ch.net/test/read.cgi/tech/1663235546/325
メモ帳
(0/65535文字)
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 677 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.021s