Sort and output the elements in the list as elements and multiples in Python.

It is a script to check for duplicate character string elements in the list using Python and output the result as multiple elements in descending order. It is expressed in inclusion notation.

python


data = ['a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'b']
result = sorted({i: data.count(i) for i in set(data)}.items(), key=lambda x: x[1], reverse=True)
print(result)

>>> [('b', 4), ('c', 3), ('d', 2), ('a', 1)]

Recommended Posts

Sort and output the elements in the list as elements and multiples in Python.
[Python] Sort the list of pathlib.Path in natural sort
Sort list elements in a specified order in Python
[Python] Manipulating elements in a list (array) [Sort]
Getting list elements in Python
[Python] How to sort dict in list and instance in list
[Python] Outputs all combinations of elements in the list
[Python] How to output the list values in order
Make sure all the elements in the list are the same in Python
Difference between list () and [] in Python
Output 2017 Premium Friday list in Python
Get the number of specific elements in a python list
Export and output files in Python
Delete multiple elements in python list
Extract bigquery dataset and table list with python and output as CSV
Difference between append and + = in Python list
Get the EDINET code list in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
[Python] Combine all the elements in the array
Extract every n elements from an array (list) in Python and Ruby
Output formatted output in Python, such as C / C ++ printf.
Output the number of CPU cores in Python
[python] Check the elements of the list all, any
Read JSON with Python and output as CSV
Make a copy of the list in Python
About the difference between "==" and "is" in python
Get only the subclass elements in a list
Output in the form of a python array
How to output "Ketsumaimo" as standard output in Python
Randomly select elements from list (array) in python
How to input a character string in Python and output it as it is or in the opposite direction.
How to remove duplicate elements in Python3 list
[Python] Precautions when retrieving data by scraping and putting it in the list
plot the coordinates of the processing (python) list and specify the number of times in draw ()
How to count the number of elements in Django and output to a template
Use libsixel to output Sixel in Python and output a Matplotlib graph to the terminal.
Sorted list in Python
Bubble sort in Python
Filter List in Python
[Memo] Python3 list sort
python input and output
List find in Python
Custom sort in Python3
Japanese output in Python
The simplest Python memo in Japan (classes and objects)
Sort in Python. Next, let's think about the algorithm.
Extract and list personal names and place names in the text
Receive the form in Python and do various things
Implemented List and Bool in Python and SQLite3 (personal note)
Merge sort implementation / complexity analysis and experiment in Python
Output the time from the time the program was started in python
[python] Get the list of classes defined in the module
Carefully understand the exponential distribution and draw in Python
[Python] Manipulation of elements in list (array) [Add / Delete]
Plot and understand the multivariate normal distribution in Python
Carefully understand the Poisson distribution and draw in Python
Get the size (number of elements) of UnionFind in Python
Find the Hermitian matrix and its eigenvalues in Python
Group by consecutive elements of a list in Python
Recursively search for files and directories in Python and output
Sort tuple list in Python by specifying the ascending / descending order of multiple keys