Last active
December 21, 2015 22:59
-
-
Save dirn/6378796 to your computer and use it in GitHub Desktop.
String Concatenation
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
| from itertools import chain, islice | |
| s1 = '4K Media' | |
| s2 = '53 W. 23rd St.' | |
| s3 = ''.join(chain(islice(filter(str.isalnum, s1), 4), | |
| islice(filter(str.isalnum, s2), 8))) | |
| assert s3 == '4KMe53W23rdS' |
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
| import string | |
| s1 = '4K Media' | |
| s2 = '53 W. 23rd St.' | |
| f = (lambda s: [i for i in s if i not in string.printable[62:]]) | |
| s3 = [None]*(12) | |
| s3[:4], s3[4: ] = f(s1)[:4], f(s2)[:8] | |
| s3 = ''.join(s3) | |
| assert s3 == '4KMe53W23rdS' |
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
| s1 = '4K Media' | |
| s2 = '53 W. 23rd St.' | |
| ss1 = [i for i in s1 if i.isalnum()][:4] | |
| ss2 = [i for i in s2 if i.isalnum()][:8] | |
| s3 = "{}{}".format("".join(ss1), "".join(ss2)) | |
| assert s3 == '4KMe53W23rdS' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment