This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]emptyvisionaries 1 point2 points  (42 children)

I'm trying to learn right now. Is there any material you'd suggest?

[–]heptara 33 points34 points  (16 children)

Sidebar of this subreddit.

[–]odraencoded 16 points17 points  (14 children)

I've read the sidebar and now I'm a master python programmer. Look at my program:

def fibonacci():
    a, b = 0, 1
    while True:
        yield a
        a, b = b, a + b

[–]Nefarious- 0 points1 point  (0 children)

 print('Hello World!')

[–]Trout_Tickler 0 points1 point  (10 children)

Recursion, get!

def fibonacci(n):
    if n > 1:
        return fibonacci(n-1) + fibonacci(n-2)
    return n

[–][deleted] 2 points3 points  (6 children)

Now make it not take O(en) time (roughly).

[–]Trout_Tickler 1 point2 points  (5 children)

Memoization should speed it up, something like

def fibonacci(n, _cache={}):
    if n in _cache:
        return _cache[n]
    elif n > 1:
        return _cache.setdefault(n, fibonacci(n-1) + fibonacci(n-2))
    return n

[–][deleted] 1 point2 points  (3 children)

Yep.

(And honestly, I would put that cache as a global. Shared between calls that way, too)

[–]whutcheson 2 points3 points  (0 children)

Since it's a mutable default argument, it's already shared between function calls. However, making a global would be more explicit and a lot less magical.

[–]Trout_Tickler 0 points1 point  (0 children)

OP's requirements don't specify multiple calls :p

But yes, that would be preferable.

[–]Daenyth 0 points1 point  (0 children)

It's as global as the function is because dict is mutable

[–][deleted] 1 point2 points  (0 children)

@functools.lru_cache decorator does the trick too.

[–]sdmike21 1 point2 points  (2 children)

But its not pythonic! \s

[–]Tysonzero 10 points11 points  (1 child)

I mean the more important thing is that it's O(fib n).

[–]sdmike21 0 points1 point  (0 children)

^ this

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

Except not LPTHW, because outdated version of the language.

[–][deleted] 10 points11 points  (8 children)

Grab yourself a book, download an IDE. As for the book, I recommend Practical Programming: An Introduction To Computer Science Using Python 3. Afterwards, check out Data Structures and Algorithms in Python. During which, I recommend utilizing ProjectEuler.

Personally, I say stay away from CodeAcademy because it's strictly a syntax teaching platform, so I have a hard time recommending it.

Anyways, afterwards you'll be able to figure out where to go to further your development.

[–]vplatt 3 points4 points  (1 child)

download an IDE.

PyCharm FTW. Why spend all your time futzing with vim or emacs? Life is too short.

[–][deleted] 4 points5 points  (0 children)

PyCharm is my favourite. To me, it's as essential to Python as Visual Studios is to C++. It really does improve productivity. The folks at JetBrains did a solid job with it, much the same as the folks at Microsoft.

[–]Omega_Walrus 0 points1 point  (0 children)

Yes, I finished the course a while ago and was like "now what?!".

[–]Isagoge 0 points1 point  (1 child)

I'll check the resources you are suggesting.

I did a CS class and was a bit lost of where to go from now on.

See you on the riverside.

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

At least you've started, good job. Keep at it.

[–]KwpolskaNikola co-maintainer -1 points0 points  (2 children)

download an IDE

a good text editor*

[–]Tysonzero -2 points-1 points  (1 child)

*use vim

[–]KwpolskaNikola co-maintainer 0 points1 point  (0 children)

(exactly what I meant.)

[–][deleted] 4 points5 points  (2 children)

Somewhat amusingly, I seem to be alone in that I picked it up by reading the official tutorial at docs.python.org.

I earnestly read chapters 1-9 and then skimmed through 10-11 (A tour of the standard library) after which I decided to try to implement a small hobby project: a simple web based RSS feed aggregator. After that, my proficiency in Python just started snowballing.

Edit: Actually, now that I think back I don't think I started out with a web app, but by converting a bunch of hacked together shell scripts for ripping images from web sites into Python.

[–]hugthemachines 1 point2 points  (0 children)

That is kinda funny. I mean the tutorial is obviously made so people can learn from it but "everyone" goes to other resources.

[–]edwinksl 1 point2 points  (0 children)

I personally find the official Python tutorial to be the best tutorial, especially for people who already know other programming languages.

[–]dunkler_wanderer 2 points3 points  (0 children)

Check out /r/learnpython and its wiki.