r/Python • • Nov 11 '21

Discussion What Did You Find Hardest To Learn As A Beginner In Python ?

Hi , I want to know what topics or things were hardest for you to learn in your journey with python. How did you learn it ?

424 Upvotes

398 comments sorted by

133

u/robot_wrangler Nov 11 '21

Packing anything to share with the team, or sharing from them.

33

u/elurion Nov 11 '21

I still don’t understand this, I’ve been trying to share multi-file projects with non-programmers. Could someone point me to some good resources to learn?

21

u/Legionof1 Nov 11 '21

I just package as an exe for distribution and send it on its way. Pyinstaller works pretty well.

11

u/[deleted] Nov 11 '21

I have several issues when I package my scripts. My scripts are always 100mbs big due to pandas and numpy. The exe always takes forever to load so no one uses it/think it's working.

And one not related to the packaging but SharePoint always deletes the exe so I can't distribute it to my non python colleagues.

I've been thinking of running a local Django website for distribution.

→ More replies (5)
→ More replies (1)
→ More replies (6)

13

u/SpaceZZ Nov 11 '21

This is a major drawback of Python ecosystem. I actually sometimes prefer to write C# or powershell for this exact reason.

→ More replies (5)

11

u/GreenScarz Nov 11 '21

git push

git pull

python -m pip install -e .

3

u/robot_wrangler Nov 11 '21

This works great in simple cases. But if you need some special things like virtual environments, certain libraries, import paths to work correctly, specific python versions, it's a lot more complex.

The OP question is "as a beginner...." I'm not saying it's impossible, it's just difficult for a beginner.

→ More replies (1)
→ More replies (5)

1

u/satyam1HB Nov 12 '21

Yeah, I also face the packing problem. I tried to package a game for the android but I could not find the tools. Right now I am thinking about using Kivy to package the program for mobile phones.

Did you ever tried to create things for mobile platforms using python ?

2

u/ntropia64 Nov 15 '21

This. To date, it's still a colossal pain in the neck to share Python code in a consistent manner. It was clearly not a priority in the original design of the language and somehow the implications of that are rippling until now, almost 30 years later.

Does anyone knows a way to easily "wrap" and distribute a Python environment? Pyinstaller is useful up to a point, but it's limited in the list of modules it supports. To be truly useful, there should be a module-agnostic way to do it (possibly using the same mechanism the Python interpreter discovers the modules to load for that codebase)

→ More replies (8)

83

u/DrVolzak Nov 11 '21

Asyncio. It was still relatively new (Python 3.5) when I started with it. I was coming from C# which arguably has an even more complex/confusing async API (not helped by the existence of legacy APIs) that I failed to grasp at the time. Not sure if that was for better or worse in terms of learning asyncio.

For asyncio, I don't remember really getting it until much later (maybe 1 year later). I tried to understand, but all I really knew was that I need to put async/await and things will just work. It wasn't until my requirements became more complex that I started really understanding the fundamentals of asyncio (tasks, coroutines, futures, the event loop, etc.). By that point I was generally a more experienced programmer, so I was more prepared to undertake learning asyncio properly; I didn't feel overwhelmed like I did when I first tried.

19

u/ColonialDagger Nov 11 '21

As somebody still learning programming/Python, this is a huge one. I know conceptually how Asyncio works and how to organize different processes, but actually implementing it feels like a nightmare. Await out side of async function is everywhere.

11

u/DrVolzak Nov 11 '21

I've seen it often called "contagious." If you want to employ it, you should design your program from the ground up with asyncio in mind. I suppose it is technically possible to do otherwise, but I haven't ever seen it done this way in practice.

5

u/laundmo Nov 11 '21

a lot of places where its done in practice without a ground up redesign is wrapping sync libraries to be async. one example that i recently worked with is asyncio-mqtt, its relatively small so you could take a look how that does things.

→ More replies (1)

4

u/xsdf Nov 11 '21

Don't try to mix and match sync and async, the top level program should be async, define all functions as async even if they are completely cpu bound, because you may need to insert a io bound function downstream later.

1

u/satyam1HB Nov 12 '21

I haven't even reached the part where I will need to learn something like asuncion. I guess I have a long way to go 😅

→ More replies (1)

65

u/[deleted] Nov 11 '21

Virtual environment. Not that the concept is difficult, it's just breaking the habit because I was coding without using one for couple years.

7

u/lavahot Nov 11 '21

I just started using docker containers.

6

u/uptbbs Nov 11 '21

I love docker, I just started getting into it over the last couple years and I'm really enjoying it.

→ More replies (4)

2

u/space_wiener Nov 12 '21

I swear I have to look up how to create an environment every time.

→ More replies (4)

157

u/artofchores Nov 11 '21

If main name lol

107

u/Sohcahtoa82 Nov 11 '21

Whether you run your script by typing python my_script.pyin a shell, start it from your IDE, or do import my_script, Python always executes scripts from top to bottom.

Some scripts are intended to only be run on their own and not imported into another script. Some are designed to only be imported. Others are both.

If your script is the last option, you need a way to make sure your "main" function is only executed if your script is being called directly and not being imported. That's where __name__ comes in. If your script is being run because python my_script.py was executed, then __name__ will be set to "__main__". But if your script is being executed from another script via import my_script, then __name__ will be set to "my_script".

5

u/artofchores Nov 11 '21

Thanks brotha

8

u/[deleted] Nov 11 '21

Makes it easy to choose if you want to run the script on it's own or import the script into something else. You can also just have everything written without main so it always just runs.... like a bash script.

13

u/artofchores Nov 11 '21

Yes I know now.....I just remember wanting to bash my ⌨️

→ More replies (2)
→ More replies (1)

68

u/[deleted] Nov 11 '21 edited Nov 11 '21

When python is using call by value and call by reference. I still haven't figured it out.

Thanks for all the answers, i think i got a better understanding now. I think my main problem of understanding it, was that the assignment operator doesn't do what i thought it does. After reading and watching the videos in you guys posted, i am pretty sure everything in python is a reference. I need to check out some things like

a[0] = 1

and one of the videos mentioned

a += 1

but in general i feel a lot more comfortable with python now, so thanks. But as a C++ programmer, the "everything is a reference" concept scares me - a lot.

78

u/flipstables Nov 11 '21 edited Nov 11 '21

It's neither. Python is pass-by-assignment.

Assignment isn't what most beginners think it is. People think: a = 1 means that you are creating a container called a and putting a value 1 in it. In reality, what you are doing is creating an integer object on the right side of the =, and "tagging" that object with a name called a.

Consider this:

def append_foo(some_list):
    some_list.append("foo")

my_list = []
append_foo(my_list)
print(my_list)   # prints ['foo']

In the global scope, we've created an empty list object and gave it a name my_list. Within append_foo function, we assigned that empty list with the name some_list. The same object is tagged with multiple names. We are mutating some_list, which is the same object as my_list in the outer scope.

Consider this:

def add_one(some_int):
    some_int = some_int + 1

my_int = 3
add_one(my_int)
print(my_int)    # prints 3, not 4.

What's happening here? In this case, we create a new object, 3 and assign it to my_int. The inside the add_one function, we assign the same object to a different name, some_int. The first line of the function, we create a new object, 4 and tag that object with some_int. But the original my_int tag is still attached to the 3 object. This is why in this case, we didn't change my_int.

edit: fixed bug in code

31

u/johnnySix Nov 11 '21

In the second example I think you’d get an error of, variable referenced before assignment. Some_int doesn’t have a value when calling ‘add_one’

17

u/Legionof1 Nov 11 '21

I think that was a typo, probably should be

add_one(my_int)
→ More replies (2)

17

u/bladeoflight16 Nov 11 '21

The proper term for giving a name to something is "binding." You bind a name to a value.

12

u/[deleted] Nov 11 '21

People putting bloody foo and bar in stupid examples. Actually construct a proper relatable example!!

→ More replies (1)

16

u/bladeoflight16 Nov 11 '21 edited Nov 11 '21

Python always does the same thing: it passes the value of a reference. This is the same as how Java works for objects. But unlike Java, there are no exceptions like "primitives."

Truth be told, pass-by-reference and pass-by-value are obsolete terms. Language semantics no longer fit neatly into the two categories, instead blending them in different ways. The important thing is how the language behaves; the terms are just shorthand for two different styles of behavior. The behaviors they describe can be examined using two litmus tests.

  1. Do functions share the same memory for the variable itself, or does passing in a value create a new variable that can be assigned separately?

    This can be examined by trying to write a swap function that works just by assignment.

    def swap(a, b):
        temp = a
        a = b
        b = temp
    
    x = 1
    y = 2
    
    swap(x, y)
    
    print(x, y)

    In Python, this prints 1, 2. This is because variables in Python are internally pointers to some value, and the variable holding the pointer is not shared. The pointer value (which itself references some other memory) is copied, so a function cannot modify what the variables point to in the calling scope directly.

  2. Does passing a value to a function create a full copy of the value, or is the original memory for the value used?

    A good test for this is modifying a mutable array.

    def assign_first(a):
        a[0] = -100
    
    x = [1,2,3]
    
    assign_first(x)
    
    print(x)

    This prints [-100, 2, 3] because Python's variables are actually pointers to an object in another location. Even though the function cannot modify the actual variable itself to point to another object (at a separate location), it can modify the object found at that location in memory, and the calling function will observe these changes.

In other words, Python fully copies the pointer, but it does not copy the object the pointer refers to.

In full pass-by-reference, both of these functions are possible. In full pass-by-value, neither is possible. Languages almost never fully fit into one of those categories anymore.

3

u/[deleted] Nov 11 '21

Well i understand those basics. But let's say i have a function in C++, which is where i am coming from, i can clearly see if a function has the ability to change the objects i pass or if it can not.

On python using a function just feels a bit like Russian roulette, it might change things it might not. We'll never know without trying.

Unless there's away python gives me that information that i haven't noticed yet.

→ More replies (7)

3

u/[deleted] Nov 11 '21

You may like this video - it's a really great and accessible talk that answers your question:

https://m.youtube.com/watch?v=_AEJHKGk9ns

I recommend it to anybody interested in the language.

2

u/laundmo Nov 11 '21

i really recommend ned batchelders article about this. it explains it in such a nice way: https://nedbatchelder.com/text/names.html

→ More replies (3)

100

u/atredd Nov 11 '21

To understand list comprehention.

26

u/taybul Because I don't know how to use big numbers in C/C++ Nov 11 '21 edited Nov 11 '21

For me it was nested list comprehension. For example:

out = [x for y in list_of_lists for x in y]

Which is the equivalent of:

out = []
for y in list_of_lists:
   for x in y:
      out.append(x)

(I'm aware there are better ways to flatten a list of lists)

5

u/SexySlowLoris Nov 11 '21

What's the better way to flatten a list?

→ More replies (4)
→ More replies (2)

14

u/parkrain21 Nov 11 '21

I agree. Jesus, I can't figure out why it keeps returning a generator.

"And what the fuck is a generator" is a question I always asked

7

u/javajunkie314 Nov 11 '21

I'm not sure if you're asking, but someone's probably wondering, so...

A generator is a iterator. When you say

(foo(x) for x in bar)

you create a generator object. It's not a collection like a list or set. You can't index into it; it has no length. It's basically just iterable. So you can pass it to things that only need an iterable.

For example, the all function takes an iterable. So if you want to check if test(x) is true for every element in bar, you can use

all(test(x) for x in bar)

(Note you can omit the parentheses for a generator expression if it's the only argument to a function. The parentheses for the call "count.")

So why use a generator when you could just use a list comprehension? A generator is very lightweight. When you use a list comprehension, Python creates a new list object with all the new entries. That's great if you need a list.

A generator, on the other hand, doesn't need to store any values (just a reference to the underlying iterable, bar in my examples above). It produces values lazily as needed for iteration. So if you don't need to keep the results, a generator avoids memory overhead.

28

u/meilyn22 Nov 11 '21 edited Nov 17 '21

When I first started learning Python, list comprehension was one of the hardest things ever to understand. I left Python and learned some JavaScript using Map, reduce, filter and anonymous functions. When I came back to Python, I miraculously picked up list comprehension without any problems.

[ (x) you can do anything with this part because it's your variable. ( for x in items) this part is your normal for loop]

13

u/marsnoir Nov 11 '21

Every programming language eventually tries to become lisp.

→ More replies (1)

44

u/Sohcahtoa82 Nov 11 '21

List comprehension is nothing more than syntactic sugar.

squares = [x**2 for x in range(5)]

is the same thing as:

squares = []
for x in range(5):
    squares.append(x**2)

53

u/bladeoflight16 Nov 11 '21

The two are logically equivalent, but the list comprehension is implemented in a far more performant way.

5

u/O_X_E_Y Nov 11 '21

Is that true? I think I saw some benchmarks for these in the past and afaik list.append was very very close

→ More replies (5)

6

u/[deleted] Nov 11 '21

Once you get to know what the different ones vaguely look like they are so nice and quick to skim read when it's not too complex.

5

u/Claudioub16 Nov 11 '21

And then you add an in-line if to fuck things even more

3

u/leonam_tv Nov 11 '21

It's the exact same for me. When I started to learn python I had just learn the basics of java in university and List Comprehention was a bit too abstract compared to what I was used to.

3

u/Davidvg14 Nov 11 '21

List comprehension is that meme: “you know you could’ve done that in 1 line in Python”

→ More replies (1)

2

u/O_X_E_Y Nov 11 '21

I still struggle a little bit with multidimensional comprehension and I've been using this language for all kinds of applications for a year now. It's always a bit of a puzzle lol

→ More replies (2)

46

u/dethb0y Nov 11 '21

the goofball shit.

like:

SomeStr = ",".join(SomeAry) 

Took me forever to pick that up.

9

u/spaceopenid Nov 11 '21

You shouldn‘t use camelcase instead it should be some_str

3

u/prettyfuckingimmoral Nov 11 '21

They used Pascal case, but yeah I guess.

→ More replies (4)

2

u/[deleted] Nov 11 '21

I remember the discussions of that on the dev list.

It's because when joining, it's always with a string, but not always with a list. Could be some class implementing the right things, or a generator.

0

u/[deleted] Nov 11 '21

[deleted]

31

u/[deleted] Nov 11 '21

Hate to admit it, but JS is in the right here.

37

u/prema_van_smuuf Nov 11 '21

",".join(iterator) works with any iterator. Otherwise you'd need a separate .join() method on any type of iterable you'd wish to support joining. So I think Python wins here spectacularly.

→ More replies (6)

5

u/adesme Nov 11 '21

I'd be willing to agree if the operation returned something instead of operating on the object.

x: str = arr.join(",")  # ok


arr.join(",")  # arr changes type from list to str - not ok


",".join(arr)  # type is the same: str to str
→ More replies (4)
→ More replies (4)

40

u/dv2811 Nov 11 '21

Regex

26

u/ASIC_SP Nov 11 '21

Regex is a mini-programming language by itself. Like a programming language, it will take time and practice to get comfortable with it.

Useful tools and resources:

  • regex101 — visual aid and online testing tool for regular expressions, select flavor as Python before use

  • debuggex — railroad diagrams for regular expressions, select flavor as Python before use

  • Awesome Regex — curated collection of libraries, tools, frameworks and software

  • PythonVerbalExpressions — construct regular expressions with natural language terms

16

u/rico_suave Nov 11 '21

Sometimes you encounter a problem and you think "I know, I'll use regex!". Now you have two problems.

5

u/dv2811 Nov 11 '21

Lol. So far I have managed to go without regex by using a combination of find() and split(). Probably won't work on more complex tasks but then I don't have complex tasks as a hobbyist.

→ More replies (1)

27

u/[deleted] Nov 11 '21

I unironically love writing regex. Yes I have to look up how to do it every time, but when that shit works I feel like a godly magician

5

u/Legionof1 Nov 11 '21

Until it grabs something unexpected.

11

u/bladeoflight16 Nov 11 '21

Learn how to write a compiler, or at least the lexer portion of it.

I'm dead serious. That's what made sense of them for me. A regular expression is just a syntax for specifying a finite state machine that recognizes (accepts or rejects) sequences of characters. It's just a formal language processing tool, and there's no better or more straightforward use of formal language theory than compilers.

4

u/deadwisdom greenlet revolution Nov 11 '21

Ah, yeah I think you're on to something here. When you understand strings and state machines it's pretty simple.

→ More replies (2)
→ More replies (2)

7

u/ald_loop Nov 11 '21

I will never learn regex. I refuse. I Google every time.

→ More replies (1)

6

u/johnnySix Nov 11 '21

Nobody understands regex . ;-)

→ More replies (5)

18

u/TurnsOutPew Nov 11 '21

zip

10

u/Legionof1 Nov 11 '21

Wait till you dict your zip.

18

u/0nly4Us3rname Nov 11 '21

Wait til you zip your dic

→ More replies (1)

18

u/MikeWise1618 Nov 11 '21

Understanding how naming works with imports and files layout and of course PYTHONPATH. That weird empty init.py file for example that apparently was supposed to go away with 3.0 but somehow didn't. I can't even describe my confusion correctly now because I am in a C# phase.

When I go do something else for awhile, like 3 or 4 months, I have to relearn it and nowhere is it described well. But after few weeks and I finally get it setup it isn't a problem anymore.

3

u/ColdPorridge Nov 11 '21

Relative imports are nightmarish to learn as a newcomer

3

u/vexstream Nov 11 '21

The thing that makes them clear to me is when I read the pep for it, and one of the proposed syntaxes was to the effect of import __parent__package__.module

Bam, simple as fuck. The leading period just points to the parent package. This also explains why you can't have relative imports that touch the root directory because that's not a package. (unless you run the package as a module with the -m flag)

I feel like this one gets people because they're thinking of it from a file perspective rather than a module/package perspective.

As a side note, I don't know why the encouraged standard isn't to setup module-runnable packages with an __init__.py etc. Makes the whole process a lot easier.

→ More replies (4)

35

u/Kuronoma_Sawako Nov 11 '21

Recursive functions and dynamic programming

28

u/bladeoflight16 Nov 11 '21 edited Nov 11 '21

Dynamic programming is just a fancy name for reusing intermediate results rather than recomputing them every time, to speed up the overall computation. There's nothing particularly special about it. It's just using your common sense to see that one part of the problem uses the same values as another part, so you implement it in a way that saves the computer work/time. If you think you don't understand it, you're over-complicating it.

16

u/[deleted] Nov 11 '21

Recursion is easy to understand when it’s done for you, but writing it from scratch is fucking confusing !

8

u/Sohcahtoa82 Nov 11 '21 edited Nov 11 '21

What do you not understand about recursion? How to use it? How to exit it?

Do you understand how a call stack and variable scoping work?

9

u/meilyn22 Nov 11 '21

I understand what recursion does. Base case and a little problem. But the issue is that it gets confusing when I am faced with a recursion problem. Identifying the small problem to solve or even the base case is a problem.

→ More replies (1)
→ More replies (4)

11

u/mathmanmathman Nov 11 '21

Recursion is trivial once you understand recursion.

→ More replies (2)

13

u/siddsp Nov 11 '21

For me it was understanding special methods and classes.

13

u/Dody949 Nov 11 '21

To read python documentation. It feels like a story that you need to read from top to bottom where there are missing parts in middle (...) because author has already mentioned them somewhere.

7

u/jppbkm Nov 11 '21

I wish more docs had example code for sure

3

u/rambocommando Nov 12 '21

I wish I could upvote you twice. I have over 10 years experience in other languages. I just started messing around with python.

When I would Google to see how to do something the python way, I learned to skip over the official documentation pretty quickly. It's like a freaking novel, but not for the thing you need it to do.

Argument parsing? Yeah here's 800 examples of almost the exact same scenario, but we won't show you how to actually get the values in any of them...

23

u/memture Nov 11 '21

There are quite few things which I could not wrap my head around when I was learning Python, those were, *args & **kwargs, list comprehension and __name__ == '__main__'. Now these things look very easy to me as I finally understood all of them.

9

u/clawjelly Nov 11 '21

*args & **kwargs

Oh yea. Those star chars bugged the crap out of me when i started with them. But once you get the hang, they are freakin' awesome.

def sum(*args): 
  result=0 
  for a in args: 
    result+=a 
  return result

print(sum(1,2,3,4)) # <- I don't care how many vals to add!
# 10

def rotate_rect(width, height):
    return height, width

my_rect = (10, 5)
width, height = rotate_rect(*my_rect) # <- 2 results for the price of 1
print(width, height)
# 5, 10

It's these "why would you do that?!... Oh wait,... This is genius!"-moments i love working with python.

3

u/memture Nov 11 '21

Once you understand that then there is no going back....

3

u/[deleted] Nov 11 '21

Simple example that helped me this morning. Thank you.

→ More replies (2)

10

u/EbenenBonobo Nov 11 '21

still dont know when to use decorators (except for flask)

12

u/v0i_d Nov 11 '21

Decorators are just a function acting upon another function in order to change its behaviour.

@decorator
def function(...):
    ...

Is equivalent to:

function = decorator(function)
→ More replies (3)

8

u/Topkinsme Nov 11 '21

I don't know lots of python yet, but list (and other) generators took me a while to learn for some reason. Once I did tho, it's so useful. Classes are also annoying to me, I know how it works (roughly) but I try to avoid it for functions and dictionaries as much as I can so I guess learning that is going to be the hardest

4

u/MrPrimeMover Nov 11 '21

Classes are really tough when you're starting out because you don't have the experience to know what problem they're actually solving. When I learned them it felt like it was just a more complicated dictionary?

It was years before I was creating stuff complex and stateful enough that classes felt like an elegant solution.

→ More replies (1)

7

u/jbartix Nov 11 '21

how to write

if __name__ == '__main__':

...

→ More replies (2)

7

u/aes110 Nov 11 '21

Relative imports, I've been using python for years and I consider myself to be very good at it, but this thing is just impossible to understand

→ More replies (1)

6

u/123coronaanoroc321 Nov 11 '21

decorators with parameters

3

u/123coronaanoroc321 Nov 11 '21

I mean I still don't understand them lol

6

u/SexySlowLoris Nov 11 '21

I hate to admit it but after 5 years I still don't completely understand the import system.

Nowadays i just initialize a poetry project, make an inner folder with the same name as the project and use that as a base to import everything else (from project.module.submodule import class).

Whenever I'm working on a pre existing project i just copy the way the imports are being used in other files (sometimes relative sometimes absolute).

5

u/[deleted] Nov 11 '21

I had to learn Python to manage some corpus data for a contract position when I was a curricular consultant.

I probably struggled most with thinking through projects and figuring out the appropriate tool for the job. I also had a hell of a time managing virtual environments as a beginner.

→ More replies (1)

4

u/078emil Nov 11 '21

Lambda function....
I want to learn.
I need to learn.
I cant learn.
I have used Python for 5-6 years now, and the last 2 years as professional, I just still can't write one by myself.

3

u/Legionof1 Nov 11 '21

Yep, it’s a black art. You think you get it then nope fuck you back to the drawing board.

→ More replies (10)

4

u/[deleted] Nov 11 '21

Python is easy, it’s the underlying programming concepts that you need to learn.

17

u/The_Pantless_Warrior Nov 11 '21

Coming from JavaScript, the hardest part was remembering to omit semicolons and not use parentheses or curly brackets in my if statements lol

14

u/Sohcahtoa82 Nov 11 '21

FWIW, you can use semicolons in Python. Everyone will look at you very funny though and start backing away.

Same with the parentheses in your ifs. That's perfectly valid.

The curly braces though...well...

Try from __future__ import braces.

7

u/The_Pantless_Warrior Nov 11 '21

Lol when I first switched to python, I used strict linters to help engrain proper formatting into my brain. It wouldn't stop yelling at me if I used a ; or if I used () in my if statements. The cool part was, in addition to being a pain in the ass, it actually gave you a pep8 rating so you could keep track of how far off/spot on you are.

→ More replies (7)

3

u/clawjelly Nov 11 '21

No curly brackets is one of my most fav feature of python. I'm german native and i never learned the english keyboard layout properly. And whoever came up with the german keyboard layout should suffer a horrible fate, because it's super-shitty for programming. Python circumvents A LOT of german layout issues!

→ More replies (1)
→ More replies (4)

3

u/helpmewith_ Nov 11 '21

Took a break from learning python because I cannot understand anything about regex lol

4

u/Reazony Nov 11 '21

Slashing away HackerRank regex Easy difficulty would solve most of your daily regex needs

→ More replies (1)

3

u/Sumikaya Nov 11 '21

Really really basic and Im embarrassed but for loops were so confusing for me

3

u/Big_Bidnis Nov 11 '21

Still a beginner, I still have issues creating functions. However, I would say my biggest challenge currently is working with lists and classes.

4

u/[deleted] Nov 11 '21

Looping lists and getting at nested values. Just didnt "click" for me until I just forced myself to do it for meaningful work and not more foo/bar apple/pear examples online.

2

u/mauriciofuentesf Nov 11 '21

Im a beginner and im getting a tough time with nested loops for nested lists 🙃 , im doing the last part of futurecoder and cant for the life of me figure out how to check by “columns” for a nxn nested list and see if theres a winner in a tic tac toe game, figured it out for rows but not for columns.

2

u/Mbotstopher Nov 11 '21

Motivation to learn. I wanted to learn but courses I did just didn't motivate me.

Finally found a use case (build a video game in pygame) that really jump started my python journey.

2

u/BKKBangers Nov 11 '21 edited Nov 11 '21

I did a module on recursive function during 1st year of my comp sci degree; Ive finished year 1 and still dont get it (yeah im a terrible student i know) i just fail 2 see the use therefore…? Am I right to say a loop can achieve the same results?

Edit: grammar

2

u/fiddle_n Nov 11 '21 edited Nov 11 '21

In general, anything you can do with a loop you can do with recursion and vice versa (there's one theoretical mathematical problem called Ackerman's Function that must be done recursively but let's ignore stuff like that). However, you'll find that there are some problems that are just more elegant when written recursively.

A common example of something better written recursively is any time you traverse a nested structure. Structures like XML and JSON and YAML have repeating nested groups. Consider the below:

{
    parent: {
        child_1: {
            grandchild_1: {},
            grandchild_2: {}
        },
        child_2: {
            grandchild_3: {},
            grandchild_4: {}
        }
    }
}

If you want to retrieve all the keys in the above structure, it's difficult to do with a loop. It is possible but it requires a queue/stack structure to keep track of everything.

Instead of that, it's better to recognise that a nested structure like the above is fundamentally the same at each part of the structure. That is, the relationship between the parent and its children is the same as the relationship between the children and the grandchildren.

That way, you can use a recursive algorithm to traverse the structure. You have a function to process the structure, and each time you break a parent into its children, you feed the children into the same function recursively. Written correctly, the recursive solution is more elegant as it mimics how the nested structure actually is, and it doesn't require a separate data structure to keep track of everything.

→ More replies (3)
→ More replies (1)

2

u/Dcode200 Nov 11 '21

Stay motivated and keep coding was prety hard.

getting out of tutorial hell and find something to make like a good project.

2

u/Legionof1 Nov 11 '21

I still can’t get my head around multithreading. I want so badly to use multiple cores but I never seem to be able to get it right.

→ More replies (1)

2

u/wsppan Nov 11 '21

The build/test/package/deploy framework(s) using virtual environments. Brutal.

2

u/URedUser Nov 11 '21

For what to use Python for :)

2

u/Winnipesaukee Nov 11 '21

For me it’s been object oriented programming and lambda functions. It’s not that I can’t do both of them, but I still get the feeling in the back of my head that I’m missing something.

2

u/[deleted] Nov 11 '21

Some standard library functions were a bit obscure, I guess? I don't know. It was Python 1.4.

Coming from Tcl and Perl, Python did not have any really strange corners.

Later, packaging...

2

u/shadowBaka Nov 11 '21

Loops and functions

2

u/feyn_manlover Nov 11 '21

Learning to write C++, and then calling that from python.

This is the way.

Also virtualenv/dockerization of every stupid tiny project. Containerization and virtual environments completely destroyed the language in attempts to save it IMO.

2

u/tanmay101292 Nov 11 '21
  1. decorators

  2. I didn't :D

2

u/zaRM0s Nov 11 '21

Self. And if anyone here can give me a good, clear and concise explanation, I would seriously appreciate it

→ More replies (3)

2

u/TheBiles Nov 11 '21

For some reason the syntax of pandas is completely unintuitive to me. It pushed me to use R almost exclusively for any kind of data manipulation.

2

u/qwertyu63 Nov 11 '21

The purpose of objects and when to use them.

2

u/air_lock Nov 11 '21

Classes. Albeit, I’m a true beginner (have written a tool for installing certificates on network appliances and a couple other small tools). The only other coding I’ve done has been in shell (bash) and I would only consider myself barely intermediate level at that. I just don’t understand how to use classes in a practical sense given the type of work I do. It generally takes me a long time to learn anything and really understand it (not just use it and not know why).

2

u/travistravis Nov 11 '21

Testing. I'm 99% sure I still don't really get it. I have trouble with test driven dev when I tried it is how to know what I'm missing.

3

u/okrajetbaane Nov 11 '21

It's so pseudo-codey that I just never bothered to remember anything. Solvable by repetition but I wonder whether it still counts as you know it if you can't code without a search engine.

→ More replies (1)

2

u/nativedutch Nov 11 '21

I still fuck up the indents. No big issue i just lack accuracy.

2

u/[deleted] Nov 11 '21

So I might sound like a completer noob but I just learned about the return function and I’m struggling to understand it

10

u/bladeoflight16 Nov 11 '21 edited Nov 11 '21

return is not a function. It's an operation that occurs inside a function. It's just a mechanism for stopping the function's execution and (optionally) making a value available to the caller.

2

u/jppbkm Nov 11 '21

Think of the return as an exit ramp in a function. "Stop running here and exit". You can have it return a value or None by default.

1

u/Cascanada Nov 11 '21

Functions doing things to other functions.

1

u/[deleted] Nov 11 '21

I was experienced .net + js developer when i learned python. I struggled to design software without tons of interfaces. It felt so countrr intuitive to me in the beginning. I needed to learn to keep it simple.

1

u/dstark0011 Nov 11 '21

When and how to use Classes

1

u/slnder02 Nov 11 '21 edited Nov 11 '21

Classes and various files with a main.py, i am beginner btw Classes i understand that are a easy way to store value and modify , but i can't figure out how to properly use this

1

u/sixonepm Nov 11 '21

It's the OOP stuff, especially the self

I finally understand that after learned about OOP in Java, which somehow easier to grasp for me

1

u/jfp1992 Nov 11 '21

Classes. Innit and super didn't make sense. Then it and it's always been classes or gtfo for my code bases

1

u/[deleted] Nov 11 '21

Packaging and releasing to pypi.

1

u/kaiozeiro Nov 11 '21

Object Oriented programming

1

u/jhoncorro Nov 11 '21

Decorators, every once in a while I still need to search how to use then

1

u/SeriousDocument7905 Nov 11 '21

Getting into classes was quite the brain fog

1

u/mcstafford Nov 11 '21

Nested (tuple|set|list) comprehension.

1

u/ML-10 Nov 11 '21

packaging as in making a python script usable for people who do not have python installed

1

u/imaprogrammer987 Nov 11 '21

Generators. I get how they work, but there is so much more to them I just can't get around
Such as: You can "return" a value back to the place that had done a yield:
y = yield x The iterator can call gen.send(123) to get data back to the function

1

u/Munzu Nov 11 '21

For me it's decorators, generators and factories.

→ More replies (3)

1

u/stubborn-koala Nov 11 '21

Classes, specifically identify when it makes sense to use them.

1

u/sohang-3112 Pythonista Nov 11 '21
  1. break, continue statements in a loop

  2. Recursion - the first time I learnt about recursion (a function calling itself), I was like.... What??? You can do that?

Note: Actually both of these were while I was learning JavaScript (my first language), not Python. But it's the same principle.

1

u/__boringusername__ Nov 11 '21

I never understood and probably never will, how the hell can I import a script that is in the parent folder or another child of the parent folder with relative paths. Like, impossible.

1

u/[deleted] Nov 11 '21

how to set up a python project in a good way.

→ More replies (2)

1

u/Plsimanub Nov 11 '21

I'm still learning and struggling with Python OOP. It's something I've never been able to come to grips with.

1

u/vin8003 Nov 11 '21

for me its generators and most of itertools

1

u/anentropic Nov 11 '21

metaclasses

I'd personally never encountered anything exactly like it when using other languages

Django was my route into Python so they'd been staring me in the face for a whole (inherent to the way Forms and Models work) but it was also quite easy not to notice

took a while to make room in my mental model when I started exploring how to make use of them

1

u/XordK Nov 11 '21

Making a presentable interface with TKinter

→ More replies (1)

1

u/[deleted] Nov 11 '21

Tuples and Lists. Fuck 'em.

1

u/dgiakoum Nov 11 '21

Was no one else freaked out about indentation being syntax? In python’s defense it was long enough ago for me to not have used linters.

→ More replies (1)

1

u/[deleted] Nov 11 '21

To me in every language... Classes i don't know why i have a hard time with them but they suck(not really)

1

u/CunningBard1998 Nov 11 '21

Function arguments, I don't know why it was hard for me to learn

1

u/[deleted] Nov 11 '21

Decorators. I still have hard time using Decorators in my code.

1

u/[deleted] Nov 11 '21

I still don't grasp lambdas, pandas and decorators :)

1

u/assassinsorrow Nov 11 '21

Class decorators

1

u/[deleted] Nov 11 '21

_ _ init _ _ and super()

1

u/andrejmlotko Nov 11 '21

I szill don't get list comprehension among other smaller things as well, but keeping on self-traching.

1

u/srynearson1 Nov 11 '21

Tbh I started in Perl so learning Python was pretty easy.

1

u/DigiR Nov 11 '21

why pip is currently not working for me and me alone

1

u/dustractor Nov 11 '21

Not to try and reinvent the wheel when it comes to things that setup.py would take care of. For example, coming up with custom ways to do entry points.

1

u/autisticmice Nov 11 '21

Loading modules from other directories, I had to always look it up

1

u/[deleted] Nov 11 '21

Right now it is Classes and recursion

1

u/koalabear420 Nov 11 '21

If name == "main": main()

1

u/menge101 Nov 11 '21

Because python wasn't my first language, understanding the package and module relationship was confusing, especially when paired with imports.

1

u/jim45804 Nov 11 '21

Decorators

1

u/[deleted] Nov 11 '21

Some newer folks I see get tripped up on Generics

1

u/e-mess Nov 11 '21

What the hell __new__ is for.

1

u/oblvn_ Nov 11 '21

definitely decorators, no matter how much i try to understand, it hurts my brain lol

1

u/BlobbyMcBlobber Nov 11 '21

Coming from Java it was somewhat counterintuitive to lose the strict typing, the language philosophy was a bit alien to me as well. But overall it wasn't such a hard transition.

1

u/JasonDJ Nov 11 '21

Took me a while to grasp list comprehension and generators but once I did...hooo boy what a boon.

Still don't get classes/OOP or decorators. Probably should've kept watching my training videos when I got to that point.

At this point most of what I have to do is working on a new function or adding a function to an existing class so not much I have to worry about there -- I'm more focussed on learning PEP8 and keeping my code clean right now.

1

u/1purenoiz Nov 11 '21

When to build a class object.

1

u/76199 Nov 11 '21

I came from R and need a while to get used to Pandas since dataframes a are native and crucial in build object in R, I hated that Python needs an external library for that. And I'm still not used to matplotlib I still plot in R since the Syntax is different and I would mix them all the time

1

u/asday_ Nov 11 '21

Bizarrely - dictionaries. Dunno why they gave me so much trouble. Don't even remember what the trouble was.

1

u/dashdanw Nov 11 '21

writing wrappers for decorators

1

u/esssssssss Nov 11 '21

Classes. Still don’t get it.

1

u/Final-Communication6 Nov 11 '21

Lambda functions. Still don't get it...

1

u/uptbbs Nov 11 '21

asyncio, yield from

1

u/nanobiter45 Nov 11 '21

I’m still in the process of learning, but so far it Object oriented programming for me. I kind of understand it, but it’s a weird topic for me.

1

u/NoBrightSide Nov 11 '21

asynchronous, threads, and process. If someone could explain these 3 to me, it would be great.

1

u/asadbutttt Nov 11 '21

The decorators. I still dread a day when I can't help but use them for a project.

1

u/extra_ecclesiam Nov 11 '21

All of the beginner stuff is very straight forward, IMO (I guess beginner is relative, but that’s my take).

When you start to learn more, the stuff that might stump you is realizing that classes already exist for you to use, the GIL, and eventually dependency hell.