+ 1

How do I compare each and every character of a string in a list of strings in python

We have a list of strings. I need to compare all the characters of first string to all the characters of other string in python

9th Sep 2020, 5:15 AM
Kavya Devaraju
5 odpowiedzi
+ 3
If you want to compare you can do by using boolean in print function directly or in if else statements. arr1 = ["name1", "name2"] arr2 = ["name3", "name1"] print(arr1[0] == arr2[0]) """ this will print false as name1 is not equal to name3""" print(arr1[0] == arr2[1]) """This will print true as name1 is equal to name1""" Same you can use in if else statements.
9th Sep 2020, 5:44 AM
Aman Kumar
Aman Kumar - avatar
+ 3
Kavya D , can you please show us your attempt? please put your code in playground and link it here. Thanks! To make sure that i got it right: lst = ['abc','cfb','xac'] # list of strings # result: a found in xac b found in cfb c found in cfb c found in xac
9th Sep 2020, 11:03 AM
Lothar
Lothar - avatar
+ 2
You need a 2d for loop. Outer loop may iterate through the string and inner loop may iterate through the list: for c in string: for s in list: #c is each character in the string #s is each string in the list #Now you can compare them here. if c == s: print(f"{c} == {s}")
9th Sep 2020, 5:59 AM
Seb TheS
Seb TheS - avatar
+ 1
For within the list you can also compare: print(arr1[0] == arr1[1])
9th Sep 2020, 5:55 AM
Aman Kumar
Aman Kumar - avatar
0
I want to compare within the list of strings not in two different lists
9th Sep 2020, 5:52 AM
Kavya Devaraju