Skip to content
Advertisement

Try to find an element in the list based on a part of the string

I have a list = [‘Assassin Bow’, ‘Bone Bow’, ‘Citadel Bow’] and I have a string = ‘Bone Bow of Fire’

How can I get output ‘Bone Bow’ as the result ? Just started codding, thx for understanding.

Advertisement

Answer

l = ['Assassin Bow', 'Bone Bow', 'Citadel Bow']
s = 'Bone Bow of Fire'

# loop through each element in list 'l'
for x in l:
    # if the element is somewhere in the string 's'
    if x in s:
        print(x)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement