Live data from Hacker News

Comprehensive Python Cheatsheet (2018)

gto76.github.io

31–40 of 83 posts

Re: Comprehensive Python Cheatsheet (2018)

#31
post #8

There are several items that are dubious at best. Why would you use no_duplicates = list(dict.fromkeys( )) instead of no_duplicates = list(set( )) ?

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

Dictionaries should not be assumed to keep their orderings anyway.

That's why there's OrderredDict.

Unless the language explicitly says that dicts hold their order, even if they do, it's an implementation detail, and it should not be relied upon.

Re: Comprehensive Python Cheatsheet (2018)

#32

Earlier quoted context omitted.

But. to do `help(thing)` you need to know what the _thing_ is. With Python, many times I vaguely know something but dunno what it is exactly. This cheatsheet solves that!

Is there some way to list all modules available for importing? Some times you don't know which modules are available to ask the help for it.

>>> help('modules')

Re: Comprehensive Python Cheatsheet (2018)

#33
post #26

Earlier quoted context omitted.

But. to do `help(thing)` you need to know what the _thing_ is. With Python, many times I vaguely know something but dunno what it is exactly. This cheatsheet solves that!

You can call help on anything . Here I am asking for help on something I have no clue about: >>> from server.db import db >>> help(db) help on Client in module google.cloud.firestore_v1beta1.client object: class Client(google.cloud.client.ClientWithProject) | Client(project=None, credentials=None, database='(default)') | | Client for interacting with Google Cloud Firestore API. | | .. note:: | | Since the Cloud Fires…

I think legends 2k means you may not know the name of a function you need to use in something you are trying to implement.

Example: Suppose you didn't know that re was what you needed for regular expression, or suppose you forgot how iterators work etc.

Re: Comprehensive Python Cheatsheet (2018)

#34
post #31

Earlier quoted context omitted.

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

Dictionaries should not be assumed to keep their orderings anyway. That's why there's OrderredDict. Unless the language explicitly says that dicts hold their order, even if they do, it's an implementation detail, and it should not be relied upon.

As of 3.7 (3.6 for cpython), dictionaries have a deterministic order.

Re: Comprehensive Python Cheatsheet (2018)

#35
post #26

Earlier quoted context omitted.

You can call help on anything . Here I am asking for help on something I have no clue about: >>> from server.db import db >>> help(db) help on Client in module google.cloud.firestore_v1beta1.client object: class Client(google.cloud.client.ClientWithProject) | Client(project=None, credentials=None, database='(default)') | | Client for interacting with Google Cloud Firestore API. | | .. note:: | | Since the Cloud Fires…

I think legends 2k means you may not know the name of a function you need to use in something you are trying to implement. Example: Suppose you didn't know that re was what you needed for regular expression, or suppose you forgot how iterators work etc.

Sure, that's why it's #2 on "2 Hard things in CS". Should probably be #1.

Re: Comprehensive Python Cheatsheet (2018)

#36
post #7

Nice, but why does this needs JS to be rendered ?

Because it's rendered directly from README.md. That way it's easier for me, because I don't have to render it every time I make a change (I make a lot of little edits all the time), and project's Github page ( https://github.com/gto76/python-cheatsheet ) always has the same content as webpage.

It's quite annoying to have to enable JS for 3 different domains just to see something other than a blank page. It also prevents non-JS browsers and retrievers from seeing content.

If you were to use e.g. org-mode for the source document, you could easily export to HTML automatically when the file is saved.

You could also easily use a git hook to run e.g. pandoc to convert md to HTML automatically.

There are many ways of automatically exporting HTML when you save the md source file. Please use one.

Re: Comprehensive Python Cheatsheet (2018)

#37
post #27
post #3

Very good page. But the best python cheat sheet is help(the_thing) . python has the second best ever help and discoverability (after Matlab of course!)

I would put it after R help function and, even better, F1 key to get the full documentation of any thing in Rstudio.

I'm amazed you think the R documentation is anything but terrible.

Compare the R vector page: https://stat.ethz.ch/R-manual/R-devel/library/base/html/vect...

To the equivalent python documentation: https://docs.python.org/3/tutorial/datastructures.html

Re: Comprehensive Python Cheatsheet (2018)

#39

Earlier quoted context omitted.

Because it's rendered directly from README.md. That way it's easier for me, because I don't have to render it every time I make a change (I make a lot of little edits all the time), and project's Github page ( https://github.com/gto76/python-cheatsheet ) always has the same content as webpage.

It's quite annoying to have to enable JS for 3 different domains just to see something other than a blank page. It also prevents non-JS browsers and retrievers from seeing content. If you were to use e.g. org-mode for the source document, you could easily export to HTML automatically when the file is saved. You could also easily use a git hook to run e.g. pandoc to convert md to HTML automatically. There are many way…

Will look into it, thanks for info.

Re: Comprehensive Python Cheatsheet (2018)

#40

Earlier quoted context omitted.

It's quite annoying to have to enable JS for 3 different domains just to see something other than a blank page. It also prevents non-JS browsers and retrievers from seeing content. If you were to use e.g. org-mode for the source document, you could easily export to HTML automatically when the file is saved. You could also easily use a git hook to run e.g. pandoc to convert md to HTML automatically. There are many way…

Will look into it, thanks for info.

Thanks for being open to the idea (unlike the downvoters). HN is so tiresome.
Post reply on HN