Last active
April 27, 2018 20:20
-
-
Save hufman/ea01877155baebcc6821e7ab811c237c to your computer and use it in GitHub Desktop.
Python puzzles
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
1 | |
2 3 | |
4 5 6 | |
7 8 9 10 | |
http://rextester.com/OUC7480 | |
import itertools | |
r = itertools.chain(range(1,11)); print('\n'.join([' '.join([str(n) for n in itertools.islice(r, l)]) for l in range(1,5)])) | |
http://rextester.com/DPXLL55930 | |
r = range(1,11); print('\n'.join([' '.join([str(r.pop(0)) for i in range(0, l)]) for l in range(1,5)])) | |
Input: 'An apple a day keeps the doctor away.' | |
Output: 'A an day the away apple keeps doctor.' # sorted words by length | |
' '.join(sorted(str.lower().strip('.').split(), key=lambda s:len(s))).capitalize()+'.' | |
test string, valid if each character exists the same count as each other character, or no string has the same count as any other | |
counts=reduce(lambda acc, i: acc.update({i:acc.get(i,0)+1}) or acc, teststr, {}); len(set(counts.values())) in [1, len(counts)] | |
test string, valid if each character found exists twice only | |
all(v==2 for v in reduce(lambda acc, i: acc.update({i:acc.get(i,0)+1}) or acc, teststr, {}).values()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment