Let's explore the "any" and "all" built-in functions in Python.
A π§΅
First of all, I'll teach you how to fish in Python before giving you the fish. ππ£
The built-in "help" function will give you documentation in Python. Make liberal use of it and reach out to it before ceding control to a search engine.
These are "aggregation" or "reducing" functions. They take a sequence and collapse it to a single value.
"any" returns if any value was truthy.
"all" returns if all values were truthy.
Functional programming like this can be great for minimizing lines of code. But it is also great for making your brain spin. Here is how I would initially write this (if I were fancy, I would use the Sieve of Eratosthenes):
Can we collapse this into fewer lines of code? Certainly, (the functional style already showed that) we can. One thing to realize is that lines 3-6 can be replaced with an any call:
I'm frequently asked: Is it easy to get a tech job?
Probably not. It will require a degree (or a lot of hard work). People who say otherwise are probably selling you something.
1/
I've taught thousands of people Python over the years. Some pick it up quickly, others really struggle. That is why Universities have "weeder" courses. To sift out the strugglers.
2/
Does that mean you can't self-learn? No, but it will take a lot more work than just sitting back and watching YouTube.
3/
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
-Kernighan's Law
π€―
When I teach programming, I emphasize that to me, the most important part is that the code is "readable."
You write code (once or twice), but it is read all the time. Optimize for what happens a lot.
Not:
π¦ Brevity
π¦ Cleverness
π¦ Using all of the features
One of the most effective things I did for my career is probably the most difficult.
π§΅π
It is not difficult because it requires strength or knowledge, it is difficult because it requires will power.
I'm talking about writing a book. π
Writing a book taught me a bunch of lessons about work, myself, and business. I would say it jumpstarted my career (even though I had been employed for over 13 years by that point). βπ§