[Python] Print strings in a list that begin with a specific character

Discussão em 'Python' iniciado por Stack, Fevereiro 8, 2025.

  1. Stack

    Stack Membro Participativo

    Currently, I have this:

    lst = ['Eleanor', 'Sammy', 'Owen', 'Gavin']

    def partition(lst):
    if any('abcdefghijklm') in ([x[0] for x in lst]):
    print(lst)
    else:
    print('This still isn\'t working')


    I am trying to examine the first character of each string in lst and only print the strings in lst that start with any letter A-M. I cannot seem to find any method that supports this. Is there any native method that I'm overlooking?

    Continue reading...

Compartilhe esta Página