Created
April 3, 2015 08:16
-
-
Save brake/9522e1af18545c5aa2f9 to your computer and use it in GitHub Desktop.
Swap nibbles python
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
def swap_nibbles(s): | |
"""Swap nibbles in a hex string. | |
len(s) must be even otherwise ValueError will be raised. | |
""" | |
if len(s) % 2: | |
raise ValueError() | |
return ''.join([y+x for x,y in zip(*[iter(s)] * 2)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment