-2

I have generated a list of tuples from a separate code to show which pairs of numbers converge (in certain equations) given different combinations of variables. I need a way to count how many of each sequence or tuple there are here in my list. Because of the way I generated the variables to begin with, the tuples are strings.

If ('1','3') is in the list 8 times, I would want to be able to return ('1''3') and the count.

converge_list=[('1', '3'), ('1', '7'), ('2', '6'), ('3', '5'), ('7', '9'), ('1', '3'), ('1', '7'), ('2', '6'), ('3', '5'), ('7', '9'), ('1', '3'), ('1', '7'), ('1', '9'), ('2', '6'), ('3', '9'), ('5', '9'), ('1', '3'), ('1', '7'), ('2', '6'), ('3', '5'), ('7', '9'), ('1', '3'), ('1', '5'), ('1', '7'), ('2', '6'), ('3', '5'), ('3', '9'), ('1', '3'), ('1', '7'), ('1', '9'), ('2', '6'), ('3', '9'), ('5', '9'), ('1', '3'), ('1', '7'), ('2', '6'), ('3', '7'), ('1', '3'), ('1', '7'), ('2', '6'), ('3', '5'), ('3', '9'), ('7', '9'), ('1', '3'), ('1', '7'), ('1', '9'), ('2', '6'), ('3', '5'), ('3', '9'), ('7', '9'), ('1', '3'), ('1', '5'), ('1', '7'), ('2', '6'), ('3', '5'), ('3', '9')]

2 Answers2

1

Probably not the most efficient solution.

for element in set(converge_list):
    print(element, converge_list.count(element))
mwo
  • 446
  • 3
  • 9
-2

You can convert the tuples to strings by str(tuple) function and count each of them using dictionary.

asgarov
  • 41
  • 6