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 turtle import Screen, Turtle | |
| pantallaa=Screen () | |
| pantalla.setup (425,225) | |
| pantalla.screensize (400,200) | |
| tortuga=Turtle () | |
| tortuga. forward (100) | |
| pantalla. exitonclick() |
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
| >>> random.choice(['Life of Brian', 'Holy Grail', 'Meaning of Life']) | |
| 'Holy Grail' | |
| >>> random.choice(['Life of Brian', 'Holy Grail', 'Meaning of Life']) | |
| 'Life of Brian' | |
| >>> suits = ['hearts', 'clubs', 'diamonds', 'spades'] | |
| >>> random.shuffle(suits) | |
| >>> suits | |
| ['spades', 'hearts', 'diamonds', 'clubs'] | |
| >>> random.shuffle(suits) | |
| >>> suits |
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 clip(text, max_len=80): | |
| """Return text clipped at the last space before or after max_len | |
| """ | |
| end = None | |
| if len(text) > max_len: | |
| space_before = text.rfind(' ', 0, max_len) | |
| if space_before >= 0: | |
| end = space_before | |
| else: | |
| space_after = text.rfind(' ', max_len) |
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 random | |
| class BingoCage: | |
| def __init__(self, items): | |
| self._items = list(items) | |
| random.shuffle(self._items) | |
| def pick(self): | |
| try: | |
| return self._items.pop() | |
| except IndexError: | |
| raise LookupError('pick from empty BingoCage') |
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 re | |
| re_numbers_str = re.compile(r'\d+') | |
| re_words_str = re.compile(r'\w+') | |
| re_numbers_bytes = re.compile(rb'\d+') | |
| re_words_bytes = re.compile(rb'\w+') | |
| text_str = ("Ramanujan saw \u0be7\u0bed\u0be8\u0bef" | |
| " as 1729 = 1³ + 12³ = 9³ + 10³.") | |
| text_bytes = text_str.encode('utf_8') | |
| print('Text', repr(text_str), sep='\n ') | |
| print('Numbers') |
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 unicodedata | |
| import re | |
| re_digit = re.compile(r'\d') | |
| sample = '1\xbc\xb2\u0969\u136b\u216b\u2466\u2480\u3285' | |
| for char in sample: | |
| print('U+%04x' % ord(char), | |
| char.center(6), | |
| 're_dig' if re_digit.match(char) else '-', | |
| 'isdig' if char.isdigit() else '-', | |
| 'isnum' if char.isnumeric() else '-', |
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
| single_map = str.maketrans("""‚ƒ„†ˆ‹‘’“”•–—˜›""", | |
| """'f"*^<''""---~>""") | |
| multi_map = str.maketrans({ | |
| '€': '<euro>', | |
| '…': '...', | |
| 'Œ': 'OE', | |
| '™': '(TM)', | |
| 'œ': 'oe', | |
| '‰': '<per mille>', | |
| '‡': '**', |
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
| private void printGuessStatistics(char candidate, int count) { | |
| String number; | |
| String verb; | |
| String pluralModifier; | |
| if (count == 0) { | |
| number = "no"; | |
| verb = "are"; | |
| pluralModifier = "s"; | |
| } else if (count == 1) { | |
| number = "1"; |
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 shave_marks_latin(txt): | |
| """Remove all diacritic marks from Latin base characters""" | |
| norm_txt = unicodedata.normalize('NFD', txt) | |
| latin_base = False | |
| keepers = [] | |
| for c in norm_txt: | |
| if unicodedata.combining(c) and latin_base: | |
| continue # ignore diacritic on Latin base char | |
| keepers.append(c) | |
| # if it isn't combining char, it's a new base char |
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
| # dial codes of the top 10 most populous countries | |
| DIAL_CODES = [ | |
| (86, 'China'), | |
| (91, 'India'), | |
| (1, 'United States'), | |
| (62, 'Indonesia'), | |
| (55, 'Brazil'), | |
| (92, 'Pakistan'), | |
| (880, 'Bangladesh'), |