I do my make-up in somebody else's car - More Late-Night Python
I do my make-up in somebody else's car - More Late-Night Python
I am on the train.
On the train I get excited and want to start coding and start blogging.
I am sorry, okay? The title is from Lorde's "Green Light". I haven't worn make-up since 2018 and that was a one-off. Literally.
100% this is true.
I might have worn it a few times before then but even then it had been a while.
I write a lot of stuff - but the blog posts that I like the most are the ones where I actually write about code.
So where am I at with the Python course?
Intermediate Python 3
- I am still watching the decorators video - I am about 7 minutes in out of 22 and so about 1/3 of the way through
- Videos are quite hard for me to watch
- I am still on the OOP lesson
- There is still quite a bit to go
- Still the rest of the lesson, a quiz, a project and something else... maybe an article maybe...
- What comes after OOP? I have given up on ever finding out. SUCH COOL TOPICS
- Unit testing
- Iterators and Generators
- Specialized Collections
- RESOURCE MANAGEMENT - AND THEN I WILL BE DONE
With intermediate Python.
But there's no rushing it for me.
I have to keep on consolidating at every step of the way.
Otherwise there's no point - sorry.
And after that the sky will be the limit. I can do the Django course.
And then I can do the Advanced Python course.
OMG AND THEN I CAN SOLVE CODING PROBLEMS.
AND OMG I CAN DO A CODEWARS PROBLEM NOW OMG.
List Filtering
Nice and simple.
Get back into it again.
I tend to go by the most popular as these tend to be the least finicky...
def filter_list(my_list: list[str,int]) -> list[int]:
# take in a new list
# loop through every item on the list
# build up a new list with only the numbers on it
# if the item is a number then add it to the list
# looks like one for typeof() in here
# or whatever it is in Python
# whatever the equivalent is in here
# okay this is looking a list comprehension isn't it then bye
Notice the above.The above is really really interesting because:
IT IS A MIXTURE OF PSEUDOCODE AND COMMENTS.
And this is really interesting because:
This is really interesting because when breaking down the steps, the procedure is:
- Write comments
- Write pseudocode
- Write the code
And I was a bit confused because I took it literally and thought it was the order. But - the first two steps especially can be intertwined. And often done in unison.
And if I didn't know that then I probably would've forced myself to do them what at a time
But as it is I know it so much better - thanks thanks thank you thank you bye.
Back to the code
Wait, WHAT. typeof() is a JavaScript thing. OOPS.
Well, this is what I wrote so far
And apparently, it is not working. NOOOOOOOOOOO.
def filter_list(my_list: list[str,int]) -> list[int]:
return [item for items in my_list if isinstance(item, int)]
nooooo. help! This code is not working and I don't understand the error. Do not replicate!!! "item" is not defined. But it just points to the last use of item in "isinstance" for now. I didn't really understand the method. How can I fix this please arrrrrrgh.
Tried this and it still isn't working
def filter_list(my_list: list[str,int]) -> list[int]:
return [item for items in my_list if type(item)==int
BOTH WERE RIGHTI just used items instead of item in my list comprehension; I got confused between writing for item in items and item for items in my_list ARRGH. Wow.
WELL AT LEAST I LEARNED TWO NEW PYTHON METHODS WHOOOOOOOOOOOOO.
This is in line with the top solutions.
I had to debug using chat gpt. It is nearly midnight. But I need to stop assuming that I am wrong.
I need to stop assuming that I am stupid and I don't know the methods.
If I knew that I was intelligent and I knew the methods, I would look more closely at the code because I would know the problems could be there as well too - thanks.
Comments
Post a Comment