0

Hi,

I have a list of lists such as : [[foo,1],[baz,1],[foo,0],[bar,3],[foo,1],[bar,2],[baz,2]]. I want to get all the different items in the inner lists and find the total number of them. I mean the result should be like : [[foo,2],[bar,5],[baz,3]]. How can I do this task?

Thanks in advance.

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pyTony
0

Using Counter looks good, but it will work only with python >= 2.7. The problem with your question is that there is no python code. Hint: start with a program which prints each list item on a different line.

0

(Default)Dictionary accessed by the first value could be good place to collet the values... Go ahead and show us your code.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.