I have a list of list like this one :
List=[['Jhon', 'Rana'], ['Rana', 'Rana'], ['Rana', 'Zhang], ['Rana', ['Z', 'Y']]
****Update: In this list, I had another structure where the first element is a single element and the second element is a list like ['Rana', ['Z', 'Y']], which means that Rana has a specific relationship with Z and R, which are not the same relationship as Rana and Jhon. ****
I want to calculate the occurence of the word of this list and I need two kind of output. The first one when we have a duplicated (or repeated word), we ignore it. The second solution, when we detect the repeated word we count it as once not twice.
Update: I want to add this type of relation to be included in the second output.
For example for the first solution the result will be Rana:2 Jhon:1 Zhang:1
the second solution will be Rana:3 (Update: will be 5 instead of 3 since we will consider Z and Y) Jhon:1 Zhang: 1
I have tried to develop the following lignes of code, but I didn´t have results:
from collections import Counter
List1=[["Rana", "Jhon"], ["Rana", "Rana"], ["Jhon", "Rana"], ["Rana", "Alex"]]
count=0
n=0
for j in range (0, len(List1)-1):
if (List1[j][0] == List1[j][1] ) or (List1[j][0] != List1[j][1] ):
count += 1
print(count)