Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Count the number of replicates in a list

I have a list like this, this is an example list:

(1, 1, 2, 2, 2, 3, 4)

I need to create a similar list but then with the number of replicates for each list item. This list will look like this:

(2, 2, 3, 3, 3, 1, 1)

All count modules I found do not support such output. Does anyone have an idea what modules to use that do support this?

Thanks!
“Nothing is impossible, the word itself says 'I'm possible'!”
PHP Code

<?php 
tup 
= (1, 1, 2, 2, 2, 3, 4)
tup_instances = tuple((tup.count(i) for i in tup))
print(
tup_instances) 
[Image: npafFhp.gif]
(Aug 14, 2017 10:11 AM)Retribute Wrote:  
PHP Code

<?php 
tup 
= (1, 1, 2, 2, 2, 3, 4)
tup_instances = tuple((tup.count(i) for i in tup))
print(
tup_instances) 

Legend!
“Nothing is impossible, the word itself says 'I'm possible'!”


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Fivepoint0Oct 23, 2018 05:24 PM 3 189 Oct 23, 2018 05:24 PM
Last Post: Fivepoint0
[Python] by Ineed2learn2eatJul 13, 2017 10:48 AM 3 228 Jul 13, 2017 10:48 AM
Last Post: Ineed2learn2eat
[Java] by AxanasMay 27, 2017 09:34 AM 7 386 May 27, 2017 09:34 AM
Last Post: Axanas