Having a Python list, containing same length strings, like the following one:
input_list = [ "abc", "def", "ghi" ]
How can I compare character by character all the strings and do the difference between them? Each string has to compare the other once.
list[0] with list[1]
list[0] with list[2]
list[1] with list[2]
Example of a comparison:
"a" with "d"
"b" with "e"
"c" with "f"
The number of string-type elements in this list may change, but the length of the strings will always be the same.
I have been struggling a lot trying to find a way to do this by either turning each element into a sub-list so I could compare them but the comparison would always give me errors in the loops such as "index out of range".
I also tried using dictionaries:
for i in range(len(list1)):n_dict["Player%s" %i] = list(list1[I])
This would give me the following output:
{'Player0': ['a', 'b', 'c'],'Player1': ['d', 'e', 'f'],'Player2': ['g', 'h', 'i']}
but then again, comparing was even more complicated with loops. I also tried by simply using list indexes such as
for i in range(len(list1):for j in range(len(list1):if ord(list[i][j]) - ord(list[i][j]) < k:player0 += 1else:player1 +=1
but always index out of range. Can someone please help me out?