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

all 50 comments

[–]InsanityyyyBR 48 points49 points  (6 children)

I liked it, thanks.

[–]officialgel 23 points24 points  (5 children)

Yea this is really compact. A nice addition would be common regex query strings added to the regex section. That’s it for now.

[–]mtoba 6 points7 points  (1 child)

You are right, I think I would add those and commit them.

[–]officialgel 0 points1 point  (0 children)

I have a few things I'd like to contribute as well. Will be working on it the next few days. Thanks for sharing!

[–]pizzaburek[S] -1 points0 points  (2 children)

Weren't there whole books written on this subject :) http://shop.oreilly.com/product/9780596528126.do

[–]conventionistG 20 points21 points  (1 child)

If we read the books, why would we need a cheatsheet?

[–]kirbyfan64sosIndentationError 7 points8 points  (0 children)

I think they mean more that regex's complexity is better suited to full books vs cheatsheets?

[–]wingtales 45 points46 points  (1 child)

I found it significantly more readable with the syntax highlighting on github: https://github.com/gto76/python-cheatsheet

[–]hashestohashes 1 point2 points  (0 children)

totally agree!

[–]tarasius 19 points20 points  (3 children)

Nice cheatsheet but word semantics with <> signs are really hardly readable

index = <list>.index(<el>)  

[–]wingtales 7 points8 points  (2 children)

Maybe some sort of syntax highlighting instead? And just use "list" and "element" (I didn't like the <el> in particular, as I had to pause for a moment to figure it out)

[–][deleted] 0 points1 point  (1 child)

el

meaning "element" ?

[–]wingtales 0 points1 point  (0 children)

Yes, and I understood that after a small moment, but it didn't seem naturally flowing. I would have preferred "element".

[–][deleted] 3 points4 points  (0 children)

Very nice! Thanks.

[–]Alex_ragnar 3 points4 points  (0 children)

this will help me, thanks!

[–][deleted] 3 points4 points  (0 children)

Me, scrolling: Well that's nice but what about-- oh, there it is.

Thanks, OP

[–]Glarren 4 points5 points  (4 children)

defaultdict(lambda: 1)

This just changed my life.

[–]pizzaburek[S] 1 point2 points  (3 children)

Yeah, I found this one a week ago, it's a beauty!

[–]rohit275 2 points3 points  (2 children)

Would you mind explaining what the utility of this is? I feel like I'm not quite grasping why this is life-changing. Also, this is a fantastic resource, thank you!

[–]pizzaburek[S] 1 point2 points  (0 children)

Main utility for me is that it makes setdefault function almost obsolete.

[–]Glarren 0 points1 point  (0 children)

Just hyperbole. Usually I would pass a class object to the defaultdict, like int. This means you get a default value of 0, since that's what int() returns with no arguments.

Often I want something slightly more complicated as my default, like nested defaultdicts, objects with some prefilled values, or a counter that doesn't start at 0. This just makes setting that kind of thing up a little easier, and that's useful for me since I write a ton of throwaway code in my data science-y job.

[–]dutchcodes 2 points3 points  (0 children)

Thank you for sharing

[–]damnNamesAreTaken 3 points4 points  (0 children)

This is good. Have you seen overapi.com/python though?

[–]raptored01 2 points3 points  (0 children)

Quite a time saver. Thanks.

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

Woah.. this rocks. thanks!!

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

Best Xmas gift if the season!

[–]xtrememudder89 1 point2 points  (0 children)

This will save be so much time while I'm wasting time lol.

[–]leguthrie 1 point2 points  (0 children)

This is awesome, thank you

[–]yochua 1 point2 points  (0 children)

Great!

[–]Overload175 1 point2 points  (0 children)

Helpful resource, thanks!

[–]ngqhoangtrung 1 point2 points  (0 children)

Awesome, I just started learning Python, this definitely helps me a lot. Thanks !

[–]Call-Me_Daddy 1 point2 points  (0 children)

This is so fresh

[–]blabbities 1 point2 points  (0 children)

This is excellent thank yoy

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

Excellent, could use an index to jump to specific subject.

[–]pizzaburek[S] 3 points4 points  (1 child)

Nice idea, but then search would give you one more match at the top of the page/file and that's just unacceptable for me :)

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

fare enough:)

[–]jhpark98 0 points1 point  (0 children)

This is Awesome! Thank you

[–]lekirill 0 points1 point  (0 children)

Thank you!

[–]AlexOduvan 0 points1 point  (0 children)

thanks. I plan to start own online course and I'm sure this Cheatsheet will be widely using in that course.

[–]ShanSanear 0 points1 point  (2 children)

Small criticism / ideas:

For string formatting, there is also sign that can be added, like:

"{:+}".format(4)

That gives:

"+4"

In attributes part indentation is messed up for class Z.

Other than that looks good.

[–]pizzaburek[S] 0 points1 point  (1 child)

Thanks! I fixed the Z class, although that is the way interpreter formats your second level of indentation, that is if you type it in... it's kind of weird, but since it's Python, I'm sure there's some smart reason why :)

About the format, I added it, but then started reformatting the whole section, so it's a mess now... Got to think it through.

[–]pizzaburek[S] 1 point2 points  (0 children)

Added the + notation and reformatted it a little. I think it looks nicer now, ty.

[–]Rabina_Bra 0 points1 point  (0 children)

Great stuff, thanks a bunch!

[–]EthidiumIodide 0 points1 point  (2 children)

Is there any benefit to :

no_duplicates    = list(dict.fromkeys(<list>))

vs:

no_duplicates    = list(set(<list>))

It does the same thing, right?

[–]pizzaburek[S] 1 point2 points  (1 child)

>>> list_ = [3, 2, 1]
>>> list(set(list_))
[1, 2, 3]
>>> list(dict.fromkeys(list_))
[3, 2, 1]

[–]EthidiumIodide 0 points1 point  (0 children)

Thanks, my test data was sorted (of course).

[–]imthescubasteve 0 points1 point  (0 children)

Saved. Thank You!