Live data from Hacker News

Comprehensive Python Cheatsheet (2018)

gto76.github.io

81–83 of 83 posts

Re: Comprehensive Python Cheatsheet (2018)

#81
post #80

Earlier quoted context omitted.

This is pretty smart. When I'm making one-off scripts I use the interactive flag python -i script.py I've programmed Python for years and never knew this. I'm not sure how well this handles errors. Tab complete works, only thing that is missing is needing to wrap help( ) to see signatures. I'm enjoying the standard lib interpreter.

I use ipython for similar task. It has wrapper for 'help' function ('?' symbol after function name), tab completion and syntax highlighting. Also it has special %hist command for easy copy-paste code.

I like IPython unless working with large arrays, because of weird memory issues I experienced (maybe they're fixed?). I miss the %run, !, %timeit magic and the IPython.terminal.debugger.set_trace().

If you're on linux it's not _that_ bad without it since the shell sort of acts like the notebook (with an equally horrible markup language). The help() and tab-complete and _ __ ___ for last 3 values works, time python .py can benchmark, -i or pdb.set_trace does the debugging. It doesn't keep a persistent history though so the workflow is sort of different.

So I use both, particularly for plots and images knowing IPython is very helpful for working with the notebooks.

Re: Comprehensive Python Cheatsheet (2018)

#82
post #56

So to get a list of unique values you suggest I convert to a dictionary and then convert back to a list? Is this the Python way? I dunno it seems like acrobatics no_duplicates = list(dict.fromkeys( ))

Easier: no_duplicates = set( )

Except that won't return a list. You need list(set()). Also using set means you lose list ordering, which isn't the case when using dict (assuming python 3.6 or higher).

That being said, and not that it should ever make a difference, list(set()) is 2-3 times faster than list(dict.fromkeys())

Post reply on HN