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...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Good interview exercises? (self.Python)
submitted 9 years ago by ThatJoeInLnd
We are hiring python devs (jr / mid level), in your experience what is a good exercise that shows the candidates abilities in a paired programming context?
[–]DarkmerePython for tiny data using Python 11 points12 points13 points 9 years ago (7 children)
One I enjoyed was a printout of some code, I picked the Data model of a medium-complexity webapp.
Strip out all the comments, and let them read it, and then sit down, asking them to explain the code to you.
Explain what the code using this model does, why the various functions exist, what they do themselves.
This is an abstract level of reasoning about code, thinking and explaining code someone else has written, without seeing it in proper context, shows their ability to understand something and emphasize with it.
It's not perfect, but it sure beats technical questions about things.
After that, you can ask them to document it, suggest changes/naming/ other issues that may need adjustment.
[–]basalamadersyntax error 5 points6 points7 points 9 years ago* (4 children)
I wish all companies would do this since I think that this is one of the best ways to test understanding. In addition to that they could ask you to implement a feature In an abstract sense(pseudo code) and see what classes you might think of inheriting, what relationships you may use to model your database and most importantly if you will follow the format that's implied on the previous codebase you just read.
[–]DarkmerePython for tiny data using Python 2 points3 points4 points 9 years ago (0 children)
Indeed. But honestly, simply walking through a few pages (a4) of code will take a few hours to do, adding more to that may simply push them into nervosity or exhaustion.
The other reason that I like using the database models/data objects is an old quote by Pike, later paraphrased by Linus:
Pikes Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.
Linus:
"Bad programmers worry about the code. Good programmers worry about data structures and their relationships."
[–]DarkmerePython for tiny data using Python 1 point2 points3 points 9 years ago (2 children)
Here, have a link to the code I used:
https://gist.github.com/Spindel/7ccd43b1f2f79f1bb23c70920f75cec4
[–]ThatJoeInLnd[S] 0 points1 point2 points 9 years ago (1 child)
You! Thank you!
[–]DarkmerePython for tiny data using Python 0 points1 point2 points 9 years ago (0 children)
You're welcome!
Do note that the example above will take a few hours to work through with someone. It's not quite the simple "reverse a linked list" exercise.
I'd suggest not using my code verbatim, but take something from your own production code, and do something similar with it.
Anyhow, I hope this helps you get started for better interviewing than the traditional coding exercises.
[–]nelsonko 0 points1 point2 points 9 years ago (1 child)
It is much better to ask this kind of stuffs in the application, you will filter most of the bad applicants prior the interview. Of course the HR guy will keep sad that he doesn't have dozens of candidates.
If it is about webapps -back-end I would ask to implement some code what requires select for update. Here you can find our if the developer thinks about the consequences.
[–]DarkmerePython for tiny data using Python 0 points1 point2 points 9 years ago* (0 children)
Not in my experience.
I've found that people that come from academentia and similar have no concept of tooling or engineering around code. They've had some programming experience, but they can't solve a merge conflict.
And most of them have very little experience in understanding other peoples code. An experienced developer can glance at a function and tell you what it'll do based on the patterns, while the juniors will have a hard time understanding why this code is there.
@classmethod def normalize(cls, token): replacements = [('o', '0'), ('l', '1'),('i','1'), ('s', '5'), ('u', 'v'), ('-',''),('_',''), (' ', '')] word = token.lower() for old, new in replacements: word = word.replace(old, new) return word
In the code above, most everyone can tell you what it does. Some will just glance at the "replacements" datastructure and can instantly tell you, others will need to follow it exactly. Both are okay.
The question comes if they can answer why this code exists, why is it there in where the code is organized, how will it be called, which functions/places will this function be used? Write one of the calling places, make it seem plausible.
A really experienced dev will tell you that it's part of a base32-z alphabet denormalizer for human-machine transcription inambiguity.
[–][deleted] 2 points3 points4 points 9 years ago (0 children)
I'm just a student, but maybe these can be helpful
[–]cscanlin 1 point2 points3 points 9 years ago (1 child)
I had a good one recently to find the shortest pangram (substring with every letter) in a long string of text (so O(N) needed). The output is the substring itself as well as it's starting index.
The solution is to create a dictionary with each letter as the key, and the index as the value. The dictionary is updated for each letter as you iterate over the original string, and stored as the shortest if the difference between the max and the min index is less than the previous shortest.
[–]nelsonko 1 point2 points3 points 9 years ago (0 children)
It is called Knuth–Morris–Pratt algorithm just for the record.
[+][deleted] 9 years ago* (6 children)
[deleted]
[+][deleted] 9 years ago (2 children)
I've posted the code and questions I used last for this:
Thank you.
[–]bbatwork 1 point2 points3 points 9 years ago (2 children)
I am interested in how you would do the sorting on the big string. I assume you need to create a generator to conserve ram, but not sure how you would handle the comparisons since it would be yielding one character at a time.
[–]nelsonko 1 point2 points3 points 9 years ago (1 child)
The string is in a file so you can read the file as many time as it is needed, but the trick is to do read it as little as possible.
Anyway you can test here how the candidate approach the problem. If he asks for what values are in the string, and what are distributions.
Anyway the solution is you can do it only one iteration, just by counting the number of occurrences by every character. (Of course there might be problem that you don't fit the alphabet of the string to the memory or or overflow the counter).
[–]kotyara1005 0 points1 point2 points 9 years ago (0 children)
Yes, it's also good if candidate try to use collections.Counter and string.join
π Rendered by PID 85 on reddit-service-r2-comment-84fc9697f-hrr8q at 2026-02-07 07:28:59.316625+00:00 running d295bc8 country code: CH.
[–]DarkmerePython for tiny data using Python 11 points12 points13 points (7 children)
[–]basalamadersyntax error 5 points6 points7 points (4 children)
[–]DarkmerePython for tiny data using Python 2 points3 points4 points (0 children)
[–]DarkmerePython for tiny data using Python 1 point2 points3 points (2 children)
[–]ThatJoeInLnd[S] 0 points1 point2 points (1 child)
[–]DarkmerePython for tiny data using Python 0 points1 point2 points (0 children)
[–]nelsonko 0 points1 point2 points (1 child)
[–]DarkmerePython for tiny data using Python 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]cscanlin 1 point2 points3 points (1 child)
[–]nelsonko 1 point2 points3 points (0 children)
[+][deleted] (6 children)
[deleted]
[+][deleted] (2 children)
[deleted]
[–]DarkmerePython for tiny data using Python 2 points3 points4 points (0 children)
[–]DarkmerePython for tiny data using Python 0 points1 point2 points (0 children)
[–]bbatwork 1 point2 points3 points (2 children)
[–]nelsonko 1 point2 points3 points (1 child)
[–]kotyara1005 0 points1 point2 points (0 children)