Last active
August 29, 2015 14:27
-
-
Save bjacobel/84aaf25f70e4d253db5d to your computer and use it in GitHub Desktop.
splat-unpack in python 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unpack(arr, unpack_into): | |
rets = () | |
for i in xrange(len(arr)): | |
if i < unpack_into - 1: | |
rets += (arr.pop(0),) | |
else: | |
rets += (arr,) | |
break | |
return rets | |
a, b, rest = unpack("1\t2\t3\t4".split("\t"), 3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment