Created
March 31, 2017 17:19
-
-
Save bmispelon/7c9664f02d4c4d816466f084feebba78 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| """ | |
| ValueError: not enough values to unpack (expected 3, got 2) | |
| ValueError: too many values to unpack (expected 3) | |
| """ | |
| def unpack(iterable, length): | |
| i = iter(iterable) | |
| ret = [x for x, _ in zip(i, range(length))] | |
| if len(ret) < length: | |
| raise ValueError("not enough values to unpack (expected {}, got {})".format(length, len(ret))) | |
| try: | |
| next(i) | |
| except StopIteration: | |
| return ret | |
| raise ValueError("too many values to unpack (expected {})".format(length)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment