Python Expertise Level – Self-Assessment
safjan.com
safjan.com
Advanced.9: "Can use Python's built-in functions like map(), filter(), reduce()."
...and knows why you should probably use comprehensions instead.
Experts.4: "Can use Python's C API to extend Python with C/C++ code."
I've written Python professionally for 20+ years. I've extended Python with C for funsies, but have never, not once, needed to do it at work. I'm glad other people have used C (and now Rust) to speed up the Python modules I want to use. I'm equally glad I've been able to use those modules, not have to enhance them with C.
Experts.7: "Understands and uses Python's garbage collection system."
99% of what you need to know is "don't write circular references".
Experts.10: "Have a good understanding of Python's internals, such as bytecode, the Python interpreter's execution model, and how Python's data types are implemented at the C level."
See Experts.4. I've had a nice career writing code in Python, but haven't had to hack on the CPython codebase. I bet there are lots of people who are experts in C who've never written a line in the GCC or Clang codebases.
This. The author does not seem to know that (1) reduce is not a built-in function anymore, and (2) map and filter were also planned to be removed from Python 3 [1]:
> About 12 years ago, Python aquired lambda, reduce(), filter() and map(), courtesy of (I believe) a Lisp hacker who missed them and submitted working patches. But, despite of the PR value, I think these features should be cut from Python 3000.
> Update: lambda, filter and map will stay (the latter two with small changes, returning iterators instead of lists). Only reduce will be removed from the 3.0 standard library. You can import it from functools.
[1] https://www.artima.com/weblogs/viewpost.jsp?thread=98196
It’s easy to chain map and filter statements without losing readability. I think I might be in the minority though.
Theres nothing wrong with using them but what you are going to find across the community are comprehensions. They concisely bring the data container and the iteration together with no fuss.
If you need to map and reduce and filter and want to build a chain and/or have reusable predicate functions then go for it.
I always encourage my teams to reach for the ecosystem usage before doing things because another language does it different (map/filter/reduce being the best option in JS 90% of the time).
But maybe you work at a functional shop and everyone Gets It(tm) and then it is the norm.
There also seem to be really stong opinions about what is idiomatic. I find writing python without lots of typehints and a good IDE to be infuriating, but I've been told type hints aren't pythonic.
There’s a bajillion ways to do everything. We use print() now, but not raise(). f-strings or .format()? Maybe c-style string formatting? How about dict formatting? Is adding strings ever permissible? Didn’t we used to use single quotes? I thought that was pythonic too.
Pythonic doesn’t exist. What’s popular is all there is. I say let’s bring map, filter and reduce into fashion.
Well, different folks have different experiences. One of the first Python-related things I had to do for my job was implementing a Python API for a custom C library that controlled some ancient hardware.
But I've done tons of stuff in Flask. I wouldn't say you need to "Have a good understanding of Blueprints" to be a Python expert. Or "proficiency subclassing yaml.YAMLObject". Or "encyclopedic knowledge of Requests verbs". Or "strong opinions on Poetry vs Pipenv". Or "can use Ansible to configure a fleet of servers".
Those are all common Python subjects in the areas I poke around a lot. You can be an expert data engineer without knowing any of those things. Just like you can be an expert backend engineer without having used Pandas a lot.
Yes, but then you're exactly that, an expert data engineer, not an expert python programmer. Extensibility, in particular C interoperability is a core aspect of the language and it's to a non-trivial extent designed around it. Much of Python's utility rests on the fact that libraries exist who make use of this feature, especially in data science!
You can be an expert software architect in Lisp and write many programs without resorting to macros, but if you want to call yourself an expert Lisper you'll need to know your macros.
As far as the data engineer bit, that's in the context of this article, which asserts that you need to know libraries predominately used by data engineers in order to be an expert programmer. I disagree, because Python is no more "about" data science than it's "about" web services or platform development or infrastructure management.
Amen, brother. It's incredibly annoying how every new niche that Python accreted over the years, is full of people who firmly believe Python exists only for them. At one point it was LISP refugees, then markup junkies (like me), then sysadmins, then 3d artists (!), then webapp jockeys, and now it's datascience and machine learning. Every kid thinks the world is built for him, but pushing such limited worldviews can only box the community into a corner - just look at Ruby to see what happens then.
map(fun, iter) --> [ fun(x) for x in iter ]
filter(fun, iter) --> [ x for x in iter if fun(x) ]
reduce(bifun, iter, initial) --> ???
edit: I'll also add that this is made worse by the fact that itertools lacks a sliding window function. last = initial
for value in iter:
last = byfun(last, value)
However, I don't find myself writing that frequently. accum = initial
series = [accum := bifun(accum, value) for value in seq]
# result = series[-1]
To be honest, this is the first time I've used the walrus operator.(Seriously, I like that.)
x = 0
deque((x := x + 1 for _ in range(10)), maxlen=0)
print(x)
>> 10
Using deque to consume generators is an old trick documented in the itertools recipes: https://docs.python.org/3/library/itertools.html#itertools-r...We have `itertools.pairwise()` for making a sliding window of pairs, but yes, there is no function that accepts an arbitrary number of elements.
What types of situations do you use reduce for?
Also you don't need map. You can use list comprehension to replace map. But list comprehensions can't replace reduce.
Technically reduce can also replace map. The only primitive you need to do all your iterations is technically just reduce.
If you want to get more elegant than you don't even need reduce. You can eliminate all redundant primitives and use functions themselves for iteration. It's Just recursion.
Coworkers don't hate it it's more readable in general to split between map and reduce and forego looping.
It's less readable to use reduce for all looping even though technically you can.
I used to do it much more in my earlier days of python 2 in around the mid-00s. It was more often the case that there was some C library I wanted to interface back then.
It’s still useful in performance situations (high iteration counts, library writing, etc). But I find myself doing it much less often now.
Eh, but any proficient C programmer should be able to inspect the generated assembly and determine if they like the results or not.
*Advanced*
> Can use advanced Python libraries like numpy, pandas, matplotlib.
You're a data scientist and this is not "Python".
> Can use regular expressions for pattern matching in strings.
Not Python really again.
> Understands and uses Python's memory management and optimization techniques.
Wait, like thinking about how a `list()` looks like from the (false) C-level perspective? Can you fix my CPU transistors while you're at it? (yes, /s)
*Experts*
> Can use Python's C API to extend Python with C/C++ code.
Do you mean whatever FFI Python has? Otherwise this is like asking your mechanic to also make it a plane, and a submarine. After all these are all just vehicles.
> Understands and uses Python's garbage collection system.
Ref counting? Wait what?
> Have a good understanding of Python's internals, such as bytecode, the Python interpreter's execution model, and how Python's data types are implemented at the C level.
Submarine :D
My perch also lets me see here the aspects I usually don't care about. Thank you!
> You're a data scientist and this is not "Python".
Pandas and matplotlib, are a weaker case, maybe, but numpy is fairly broadly used (math being a core part of computing) library outside of just data science.
E.g., this tutorial on building a roguelike in Python has two direct dependencies, tcod (a library specifically to support roguelikes) and numpy: https://rogueliketutorials.com/tutorials/tcod/v2/part-0/
True, but Python can still do maths without numpy. Also I don't think "building a roguelike" is a typical example of a real-world programming task.
Lots of backend/platform engineering uses math, but not always enough to justify adding such a huge dependency.
I guess it's easy to pick on any rubric, but I found the implication of this one be unhelpful. I like the training materials that focus on continual development instead -- I don't recall any off the top of my head, but they provide a contextual learning path, like if you've mastered list comprehension now take a look at decorators.
Interestingly in my 15 years of Python I’ve used numpy sparingly for image processing and haven’t used the others ever. I appreciate this isn’t meant to be an exhaustive checklist but it reminds me how two advanced coders could live in two entirely different drawers of the tool chest.
That's not "python" for me.
In most circumstances, I feel like using metaclasses is a red flag. How many people are there on earth who understand and regularly use meta classes when they're appropriate? I always pegged metaclasses as "you should know this exists in case you ever get unlucky enough to need it but otherwise stay the hell away from it"
The worst thing about metaclass is that 95% of python programmers look at it and just go "whuzzat?" and require a seminar to catch a clue. It's actively hostile to whoever maintains the code after you.
I agree with you in that it's nice to know that metaclasses exist, and that you can potentially reach for them in a pinch.
I also think you can go really far in Python development without ever needing to know about metaclasses.
I once used metaclasses because I was writing a code generator for a DSL. But that was the only time.
Conceptually they're not too difficult but more likely than not YAGNI.
People that know what a namespace package is and how __init__.py works.
I care more about operating the toolchain efficiently and writing understandable code and avoiding "advanced" patterns until forced to use them for business impacting constraints (performance).
Use simple data classes or vanilla classes without a lot of methods. Functions that take objects in and dont mutate them.
Readable and understandable by folks new to the org and the team. And juniors.
People who care about the impact of maintaining code and put the effort into effective documentation and code comments.
Among other issues, many of the criteria for "expert" sound more like the criteria for "library developer". Many conventionally-expert application developers and data scientists would smartly not use those features and may self-assess themselves out of the category for lack of active practice. Meanwhile, too many conventionally-junior developers would sophomorically insist that they can and should use them and self-assess themselves as experts.
I would disagree that someone's knowledge of third-party libraries helps determine how good they are at Python. Why not ask about the `array` package?
What about using the functional builtin packages (eg - itertools, functools)?
Memory management and optimizations are negligible, but I'd lump hose in with expert since I rarely see one of the
I just worry, when I see a list of things tagged "expert" like this, that people will take it as a learning path, which... Could be good, but there are much straighter paths to learning to be effective as a developer.
I don't think this is a very good assessment point of someone's python proficiency.
Maybe substitute those with itertools, functools, and array builtin packages.
Personally I think a few things actual experts should know are:
- python packages: pip vs package manager vs conda
- python 2 vs 3 differences and porting
- os peculiarities, such as windows vs linux
etc...
An expert will relearn the differences if/when it needs to be done.
And understands why Python sucks for this use case.
Toolchain savvy would seem a precursor to doing C/C++ extensions down in the Expert section.
What are these?
Those are all under the heading of conserving memory, nothing to do with explicit memory management. If I needed that tight of control, I would not be writing Python.
[1] https://realpython.com/lessons/small-integer-caching/#descri... [2] https://docs.python.org/3/c-api/long.html#c.PyLong_FromLong
Typical blind leasing the blind in service of everyone wanting to become a “content creator”.
The degree to which the ‘Python data science’ scene has their own separate set of conventions, and the degree to which there’s a lot of weird meta-programming going on in these packages, is quite jarring.