Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
この質問はPython - 辞書で最も長い (ほとんどの単語) キーを見つける -に似ていますが、純粋な文字数が必要です。
入力例:
d = {'group 1': 1, 'group 1000': 0}
出力:
10
>>> max(len(x) for x in d)
また
>>> max(map(len, d))
>>> d = {'group 1': 1, 'group 1000': 0} >>> len(max(d, key=len)) 10
このソリューションは最速ですが、@eumiroと@ms4pyによるソリューションを好みます。これらは、len関数を2回繰り返さず、よりpythonicimoであるためです。
len