Friday, July 8, 2022

to get index of an element with substring and pop an element from a list with sub string

 

test_list = ['GeeksforGeeks', 'Geeky', 'Computers', 'Algorithms']
print(test_list.pop(1))
print(test_list)
def getsubind(sub,l):
    for i in range(len(l)):
        if sub in str(l[i]).lower():
            return i
    return None

def popElement(sub,l):
    for i in range(len(l)):
        if sub in str(l[i]).lower():
            l.pop(i)
    return None

print(getsubind('gori',test_list))
print(popElement('gori',test_list))

No comments:

Post a Comment