{"description":"Ruby\u306e\u5148\u982d\u306e\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u5225\u306b\u8981\u7d20\u3092\u30b0\u30eb\u30fc\u30d7\u5206\u3051\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3092\u66f8\u304d\u63db\u3048\u3066\u307f\u308b\u3002 \u304c\u3001\u3061\u3087\u3063\u3068\u30b3\u30b1\u305f\u3002 groupby\u306e\u6319\u52d5\u3092\u898b\u3066\u307f\u3088\u3046\u3002 from collections import defaultdict from itertools import groupby animals = [\"cat\", \"bat\", \"bear\", \"camel\", \"alpaca\"] d = defaultdict(list) for k, g in groupby(animals, key=lambda x: x[0]): d[k].append(list(g)) print list(g) \"\"\" \u2026","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fxef.hatenadiary.org%2Fentry%2F20120416%2Fp1\" title=\"itertools.groupby\u3092\u4f7f\u3063\u3066\u307f\u308b - Soleil cou coupe\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","published":"2012-04-16 00:00:01","version":"1.0","categories":["Python"],"image_url":null,"type":"rich","height":"190","provider_url":"https://hatena.blog","author_name":"xef","title":"itertools.groupby\u3092\u4f7f\u3063\u3066\u307f\u308b","blog_title":"Soleil cou coupe","provider_name":"Hatena Blog","url":"https://xef.hatenadiary.org/entry/20120416/p1","author_url":"https://blog.hatena.ne.jp/xef/","blog_url":"https://xef.hatenadiary.org/","width":"100%"}