Answers for "py part of string is in array"

2

python return first list element that contains substring

# Example usage:
your_list = ['The answer to', 'the ultimate question', 'of life', 
     'the universe', 'and everything', 'is 42']

[idx for idx, elem in enumerate(your_list) if 'universe' in elem][0]
--> 3 # The 0-based index of the first list element containing "universe"
Posted by: Guest on September-28-2020
6

if string is in array python

if item in my_list:
    # whatever
Posted by: Guest on August-31-2020

Code answers related to "py part of string is in array"

Python Answers by Framework

Browse Popular Code Answers by Language