Given my list
myListOf=[("a", "b"), ("a", "c"), ("a", "d")]
I want to know how many time a
is repeated in list
I tried with a empty list, iterate myListOf
and append, and use collection.Counter
to return the values. Is the best way to do it?
counter_one = []
myListOf = [("a", "b"), ("a", "c"), ("a", "d")]
for i in myListOf:
for e in i:
counter_one.append(e)
print(Counter(counter_one))
>>> Counter({'a': 3, 'b': 1, 'c': 1, 'd': 1})
This for my use case is kinda... "weird", because this can be huge...
This is use case:
I have to connect to a DB and write the data into CSV, I have all of this done and working, but now I have to know the most repeated value from a column
SELECT col_one, col_two, col_three FROM table_name
This return a list of tuple and I have to say The most repeated in col_one is SOME_VALUE
, if I use my current method, I can't access to a specific column (I append all values).