Skip to content
Advertisement

python: get percentage from collection counter

I have two lists like the following:

JavaScript

I have tried to get the counts of elements in the first list based on a condition:

JavaScript

the output is:

JavaScript

instead of counts, I would like to get their percentage like the following

JavaScript

I have tried adding Counter(100/([a for a,b in zip(l1,l2) if b=='f'])), but I get an error.

Advertisement

Answer

You can try this:

JavaScript

To calculate percentage:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement