Skip to content

Instantly share code, notes, and snippets.

@yinian1992
Last active November 19, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yinian1992/b353b0b44fa6893e8e7a to your computer and use it in GitHub Desktop.
Save yinian1992/b353b0b44fa6893e8e7a to your computer and use it in GitHub Desktop.
The most god-stick-like code written in Python this year.
# God-stick-like
from itertools import chain, repeat
from functools import partial, reduce
this_is_a_list = [1, 2, 3, 4, 5]
what_you_want = reduce(chain, map(partial(repeat, times=2), this_is_a_list))
# Normal
this_is_a_list = [1, 2, 3, 4, 5]
what_you_want = [val for val in this_is_a_list for i in range(2)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment