マークを覗いて、数字側でカウントしたい。
マーク別にカウントされていて、数字側のカウント上手く取れません。
python
1 2l=[[1, '♧'], [2, '♡'], [12, '♤'], [0, '♤'], [9, '♢'], [10, '♢'], [12, '♧'], [0, '♡'], [6, '♤'], [11, '♧']] 3 4print(l) 5import collections 6[print(collections.Counter(i)) for i in l] 7 8T=[collections.Counter(i).keys() for i in l] 9print(T) 10
#出力
python
1Counter({1: 1, '♧': 1}) 2Counter({2: 1, '♡': 1}) 3Counter({12: 1, '♤': 1}) 4Counter({0: 1, '♤': 1}) 5Counter({9: 1, '♢': 1}) 6Counter({'♢': 1, 10: 1}) 7Counter({12: 1, '♧': 1}) 8Counter({0: 1, '♡': 1}) 9Counter({'♤': 1, 6: 1}) 10Counter({11: 1, '♧': 1}) 11[dict_keys([1, '♧']), dict_keys([2, '♡']), dict_keys([12, '♤']), dict_keys([0, '♤']), dict_keys([9, '♢']), dict_keys(['♢', 10]), dict_keys([12, '♧']), dict_keys([0, '♡']), dict_keys(['♤', 6]), dict_keys([11, '♧'])]
#望む出力
python
1Counter({0:2},{1:1},{2:1},{6:1},{9:1},{10:1},{11:1},{12:2})
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。