5 Réponses
+ 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.
+ 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
+ 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}")
+ 1
For within the list you can also compare:
print(arr1[0] == arr1[1])
0
I want to compare within the list of strings not in two different lists