Checking a variable against a list and seeing if a word in that list starts with the variable
<p>I'm trying to write a function that uses a checker that could be any length and checks it against the list. It should be case insensitive when checking and print the word. Example below</p>

<p><code>Input= startsWith('a',['apple','ApPle','orange','Apple','kiwi','apricot'])</code></p>

<p><strong>Output:</strong></p>

<pre><code>apple
ApPle 
Apple 
apricot
</code></pre>

<p>But, it prints every string in the list all in lower case.</p>

<pre><code>def startsWith(checker,lister):

    checker.lower()
    size = len(lister)
    i=0
    checklength = len(checker)
    lister = [element.lower() for element in lister]
    while(i&lt;size):
        checkinlist = lister[i]
        if(checkinlist[0:checklength-1] in checker):
            # this is just to test to see if the variables are what i need
            # once the if statement works just append them to a new list
            # and print that
            print(lister[i])

        i=i+1
</code></pre>

<p>You should not mutate the original elements of <code>lister</code>, rather do the comparison on a new copy of those elements that has been converted to lower case.</p>

<p>It can be done in a single list comprehension.</p>

<pre><code>def startsWith(checker, lister):
    cl = checker.lower()
    return [s for s in lister if s.lower().startswith(cl)]

Input= startsWith('a',['apple','ApPle','orange','Apple','kiwi','apricot'])

for i in Input:
    print(i)
</code></pre>

<p>Output:</p>

<pre><code>apple
ApPle
Apple
apricot
</code></pre>

python