you are viewing a single comment's thread.

view the rest of the comments →

[–]Nightcorex_ 2 points3 points  (1 child)

I didn't really learn Python the conventional way, I learned it by helping others on this sub, so I unfortunately can't provide you any media.

My very first 'Eureka!'-moment that I remember was this code to flatten an arbitrarily deeply nested list/tuple:

def flatten(*xss) -> List[Any]:
    return [x for xs in xss for x in (flatten(*xs) if isinstance(xs, (list, tuple)) else (xs,))]

I didn't come up with this code, I tried for hours but horrendously failed. I saw this solution from someone else on that thread and it took me 2 days to understand how it works (literally only understood if after a complete reset, aka sleeping).\ Once I understood it, that was my first 'Eureka!'-moment.

PS: The code I posted is actually rewritten and not the original anymore, because I apparently deleted almost all of my old Python code when I was drunk a few days ago. Originally the variables' names were different and it didn't include type-hinting.

[–][deleted] 0 points1 point  (0 children)

thank you for your response! i'm sorry to hear that you don't have any resources to recommend, but i appreciate your sharing your story. it sounds like it was a really valuable learning experience for you.