Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on The most elegant implementation of FizzBuzz. Parent comment
Treating a dictionary as an iterator automatically iterates over its .keys(), so you can remove the .keys() in fb.keys() and just map over fb itself.
>>> map(lambda x: x+x, {2: "who", 4: "do", 6: "we", 8: "appreciate"})
[16, 4, 8, 12]
A problem that this highlights is that the order in which the Fizz and Buzz and other strings get concatenated depends on the order of the underlying dictionary hash, which can be thought of as random. In Python 3 it even changes from run to run.
https://docs.python.org/3/whatsnew/3.3.html#summary-release-...
$ python3 -c 'print(list({"foo": "bar", "baz": "qux"}))'
['foo', 'baz']
['baz', 'foo']
For predictable behavior across larger sets of divisors, and for consistent behavior on Python 3, you'd probably want to use collections.OrderedDict.
There are no comments on this comment yet.
Treating a dictionary as an iterator automatically iterates over its .keys(), so you can remove the .keys() in fb.keys() and just map over fb itself.
>>> map(lambda x: x+x, {2: "who", 4: "do", 6: "we", 8: "appreciate"})
[16, 4, 8, 12]
A problem that this highlights is that the order in which the Fizz and Buzz and other strings get concatenated depends on the order of the underlying dictionary hash, which can be thought of as random. In Python 3 it even changes from run to run.
https://docs.python.org/3/whatsnew/3.3.html#summary-release-...
$ python3 -c 'print(list({"foo": "bar", "baz": "qux"}))'
['foo', 'baz']
$ python3 -c 'print(list({"foo": "bar", "baz": "qux"}))'
['baz', 'foo']
For predictable behavior across larger sets of divisors, and for consistent behavior on Python 3, you'd probably want to use collections.OrderedDict.