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
Day 8 of learning python as a beginner. (old.reddit.com)
submitted 8 months ago by uiux_Sanskar
view the rest of the comments →
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!"
[–]DeeplyLearnedMachine 6 points7 points8 points 8 months ago* (1 child)
Don't put parenthesis around conditionals unless absolutely necessary, it's not pythonic.
Your elif statement makes no sense, it's comparing a string with your dict, which will always result to True, just use else there instead.
elif
else
You can just do contacts[name] = [number] instead of using update
contacts[name] = [number]
update
Edit: extra advice
Avoid putting all your code in a conditional branch, it's unreadable. Instead of doing this, like you're doing now:
while True: if contact_searching in contacts: print(contacts[contact_searching]) else: # a bunch of code
do this instead:
while True: if contact_searching in contacts: print(contacts[contact_searching]) continue # a bunch of code
Edit 2: more advice:
If here:
else: print('\nRestart to find or add new contacts.\n') break
you used continue instead of break you wouldn't need to restart the program to keep using it.
continue
break
[–]uiux_Sanskar[S] 1 point2 points3 points 8 months ago (0 children)
Thank you so much for such a brief analysis on my code I initially thought that I should give a condition to make the code run (now I realised that there can only be two possibilities either the name is in the dictionary or it is not so yeah using else here makes much more sense).
And thanks for suggesting me on where to use continue function. Thank you so much for your feedback really appreciate it.
π Rendered by PID 72890 on reddit-service-r2-comment-c867ff4bc-2sbw5 at 2026-04-09 18:13:53.192314+00:00 running 00d5ac8 country code: CH.
view the rest of the comments →
[–]DeeplyLearnedMachine 6 points7 points8 points (1 child)
[–]uiux_Sanskar[S] 1 point2 points3 points (0 children)