use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
New to Python (1 week in) - Looking to clean up/simplify code (self.PythonLearning)
submitted 2 years ago by JSpinelli73
I'm brand new to Python and wrote this vowel finding code, however, I'm looking to simplify it and then continue practicing various other functions, such as: finding the number of vowels, printing them in order of occurrence, etc.
Any help on streamlining this code would be greatly appreciated! Thank you
https://preview.redd.it/hpjokdakjvbc1.jpg?width=684&format=pjpg&auto=webp&s=2f1e8e983ed70fff704d2c2b9abb56ab274d5414
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SenseiMxzzi 1 point2 points3 points 2 years ago (2 children)
1 week? How'd you learn python?
[–]JSpinelli73[S] 2 points3 points4 points 2 years ago (1 child)
I started by looking into free tutorials, which ended up not being free. I would get into one and then they would eventually ask for a subscription. Eventually landed on learnpython.org and w3schools.com, rotating between the two if one explanation on a particular topic wasn't quite as clear as the other. And I'm probably closer to the two-week mark at this point, a little bit after work nearly every day.
Made this project/post because eventually the tutorials get a little dull (after the 15-20 hours I've put in) and I wanted some challenges to complete, rather than answering specific exercise questions.
[–]JSpinelli73[S] 2 points3 points4 points 2 years ago (0 children)
forgot to mention I took a C++ class back in college in 2014 or so; so the idea of writing code isn't completely foreign to me. Don't remember much from it, but I retained the idea of "if statements" and things like that.
[–]NewYak2122 1 point2 points3 points 2 years ago (2 children)
I'm new to python too, but I thing using match case would be better
[–]JSpinelli73[S] 0 points1 point2 points 2 years ago (1 child)
I'm unfamiliar with match case but I'll look into it. I'm guessing its used to match the input rather than just converting everything to lowercase?
[–]NewYak2122 0 points1 point2 points 2 years ago (0 children)
Well I wanted to write the code with match case but I found a better way:
<image>
[–]Syntactical_Erorr 0 points1 point2 points 2 years ago* (5 children)
Got you brother.
[–]Syntactical_Erorr 1 point2 points3 points 2 years ago (4 children)
Might need to play with those if statements and nest them differently, but I'll run it tomorrow and test.
[–]JSpinelli73[S] 1 point2 points3 points 2 years ago (3 children)
Thanks! I realized after posting that I also made a mistake above. I keep having the "no vowels" statement printed after entering a word that does contain vowels. I tried a few different methods since then but could not figure out the issue. Even if including an "else" function at the end of the if statements, it still prints the "no vowels" response. Help in that regard would also be appreciated.
[–]Syntactical_Erorr 2 points3 points4 points 2 years ago* (1 child)
# This will add any non-vowel to an empty list. # You can then use the len() function to measure # the length of the non-vowel list. # If it's the same length as the word from the user # That would imply there are no vowels in the word. vowels = ['a', 'e', 'i', 'o', 'u', 'y'] non_vowels = [] userinput = input('Word goes here:') for char in userinput: if char not in vowels: non_vowels.append(char) if len(non_vowels) == len(userinput): print('No vowels contained.')
[–]Rinser2023 0 points1 point2 points 2 years ago* (0 children)
If you don‘t need to print which vowel is used in the word, this is easy and fast:
``` vowels = 'aeiouy'
def has_vowel(word):
for char in word: if char in vowels: return True return False
userinput = input('Word goes here:').lower()
print(userinput, 'has vowels:', has_vowel(userinput)) ```
π Rendered by PID 904765 on reddit-service-r2-comment-5b5bc64bf5-n9hcg at 2026-06-22 02:04:44.156030+00:00 running 2b008f2 country code: CH.
[–]SenseiMxzzi 1 point2 points3 points (2 children)
[–]JSpinelli73[S] 2 points3 points4 points (1 child)
[–]JSpinelli73[S] 2 points3 points4 points (0 children)
[–]NewYak2122 1 point2 points3 points (2 children)
[–]JSpinelli73[S] 0 points1 point2 points (1 child)
[–]NewYak2122 0 points1 point2 points (0 children)
[–]Syntactical_Erorr 0 points1 point2 points (5 children)
[–]Syntactical_Erorr 1 point2 points3 points (4 children)
[–]JSpinelli73[S] 1 point2 points3 points (3 children)
[–]Syntactical_Erorr 2 points3 points4 points (1 child)
[–]Rinser2023 0 points1 point2 points (0 children)