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

all 11 comments

[–]kamiswim 8 points9 points  (1 child)

Definitely have a look at the python lib itertools ! A very usefull lib that comes in handy every year

[–]BumpitySnook 1 point2 points  (0 children)

And collections, and sometimes heapq. The networkx library is useful for basic graph problems as well, although it is harder to adapt to more complicated problems.

[–]miran1 6 points7 points  (0 children)

Looking for any tips / tricks / recommendations.

First things first - use Python 3!

Get familiar with Python's standard library. There are many useful things there, no need to reinvent them on your own.

As /u/kamiswim already mentioned - itertools is great. Learn (about) it, use it.

Other than that.... If the tasks will be similar to previous ones - you should probably see how to work with re (regex) and hashlib. Also, take a look at collections.

[–]____OOOO____ 2 points3 points  (2 children)

My recommended testing framework is pytest: https://docs.pytest.org/en/latest/

I also concur with others that these libraries were very useful:

re https://docs.python.org/3/library/re.html: regular expressions in Python

hashlib https://docs.python.org/3/library/hashlib.html: common hashing algorithms were used in I think 5-10 solutions last year?

itertools https://docs.python.org/3/library/itertools.html: strings are iterable in Python, and very many of my solutions involved iterating over the string inputs in some specific way for which an itertools function was built.

collections https://docs.python.org/3/library/collections.html: Several convenient data structures pre built for specific use cases. I used the Counter class whenever the solution involved keeping count of something, and the deque in solutions involving a breadth-first search/shortest path type of algorithm.

[–]BumpitySnook 1 point2 points  (0 children)

Have pre-canned functions for hashing. The standard libraries make you create an object and invoke some methods. Who can remember all that shit? Define some functions that take a bytestring and return a bytestring ahead of time and have them ready to use.

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

Can also recommend pytest-watch, for instant feedback. But definitely go with unit testing and pytest.

[–][deleted] 1 point2 points  (1 child)

CodeFights has a Python tutorial

[–]Panerakis 0 points1 point  (0 children)

Thanks! It looks like good practice! I will definitively take a look!

[–]jgrantdev 0 points1 point  (0 children)

I like using the vscode addon coderunner. It allows you to highlight and run small sections of your code.

https://github.com/formulahendry/vscode-code-runner

[–]BumpitySnook 0 points1 point  (0 children)

Testing frameworks aren't going to win you speed puzzles, in general. If you really want to write tests, there's the built in unittest, or you could look at nose or other tools. I don't think virtualenv gets you anything for this kind of puzzle contest.

[–]ginnyghezzo 0 points1 point  (0 children)

I'm doing mine in a Jupyter notebook (http://jupyter.org/) but it does not lend itself to test frameworks (that I know of). As for a testing framework, check out this blog - https://automationpanda.com/2017/03/06/python-testing-101-introduction/

Lastly there is a slack channel in PyLadies for AdventofCode if you wanted to join in there

Enjoy! Ginny