Python Beginner - How to generate a list and frequency from another list -


given:

[['x','a'], ['y','b'], ['z','a']] 

i list of elements , count frequency of 2nd element:

[['x','a',2], ['y','b',1], ['z','a',2]] 

>>> collections import counter >>> l = [['x','a'], ['y','b'], ['z','a']] >>> freq = counter(y x, y in l) >>> [[x, y, freq[y]] x, y in l] [['x', 'a', 2], ['y', 'b', 1], ['z', 'a', 2]] 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -