Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python list group by count

>>> a = [1,1,1,1,2,2,2,2,3,3,4,5,5]
>>> d = {x:a.count(x) for x in a}
>>> d
{1: 4, 2: 4, 3: 2, 4: 1, 5: 2}
>>> a, b = d.keys(), d.values()
>>> a
[1, 2, 3, 4, 5]
>>> b
[4, 4, 2, 1, 2]
Comment

PREVIOUS NEXT
Code Example
Python :: how to convert a list into string with  
Python :: How to count occurences of a certain item in a numpy array 
Python :: python cache return value 
Python :: add element to heap python 
Python :: how to get the index of a value in pandas dataframe 
Python :: import crypto python 
Python :: os run shell command python 
Python :: turn off grid in matplotlib 3d 
Python :: new working version of linkchecker 
Python :: how to change cursor on hover of button in tkinter 
Python :: python replace regex 
Python :: python multiply all elements in array by constant 
Python :: is root node an internal node 
Python :: start django project 
Python :: text to binary python 
Python :: How to add card in trello API using python 
Python :: how to open a website with selenium python 
Python :: pandas extract month year from date 
Python :: how to close the window in pygame 
Python :: how to make nmap port scanner in python 
Python :: python list inversion 
Python :: panda - subset based on column value 
Python :: is alphabet python 
Python :: export sklearn.metrics.classification_report as csv 
Python :: python string remove whitespace and newlines 
Python :: convert bytes to numpy array python 
Python :: update windows wallpaper python 
Python :: python send email outlook 
Python :: directory name python 
Python :: how to use colorama 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =