OverflowError: (34, ‘Result too large’)

Python floats are neither arbitary precision nor of unlimited size. When k = 349, 16.**k is much too large – that’s almost 2^1400. Fortunately, the decimal library allows arbitrary precision and can handle the size:

Get a random sample with replacement

I have this list: and I want to get 4 random letters from it, but including repetition. Running this will only give me 4 unique letters, but never any repeating letters: How do I get a list of 4 colors, with repeating letters possible?

BeautifulSoup and lxml.html – what to prefer?

The simple answer, imo, is that if you trust your source to be well-formed, go with the lxml solution. Otherwise, BeautifulSoup all the way. Edit: This answer is three years old now; it’s worth noting, as Jonathan Vanasco does in the comments, that BeautifulSoup4 now supports using lxml as the internal parser, so you can … Read more