Click here to Skip to main content
15,793,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How could I print all items of a list that begin with a certain character (taking a list of strings and a character as parameters) when capitalization of the character and the first letter of the string should not make a difference in whether the string is printed or not?

What I have tried:

def partition (strings, char):
    if strings == []:
        print('')
    else:
        for string in strings:
            if string[0] == char:
                print(string)
Posted
Updated 31-Jan-17 5:56am
v2

1 solution

turn them into the same case before comparing:
if string[0].upper() == char.upper():
 
Share this answer
 
v2
Comments
Peter Leow 31-Jan-17 11:12am    
What were you doing? Are you sure you understand the code or just got it from some where? You are making it worse. It is supposed to replace this
if string[0] == char:
Member 12975993 31-Jan-17 11:16am    
Definitely wrote it myself, just a really confused beginner. But I see how that applies now. Thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900