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 timeit import timeit | |
| def make_list_1(): | |
| result = [] | |
| for value in range(1000): | |
| result.append(value) | |
| return result | |
| def make_list_2(): | |
| result = [value for value in range(1000)] |
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 process_cities(filename): | |
| with open(filename, 'rt') as file: | |
| for line in file: | |
| line = line.strip() | |
| if 'quit' in line.lower(): | |
| return | |
| country, city = line.split(',') | |
| city = city.strip() | |
| country = country.strip() | |
| print(city.title(), country.title(), sep=',') |
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 dump(func): | |
| "Return arguments and outputs" | |
| def wrapped(*args, **kwargs): | |
| print("Function name: %s" % func.__name__) | |
| print("Input arguments: %s" % ' '.join(map(str, args))) | |
| print("Input keyword arguments: %s" % kwargs.items()) | |
| output = func(*args, **kwargs) | |
| print("Output:", output) | |
| return output | |
| return wrapped |
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 just_do_it(text): | |
| #Capitalize all words in <text> | |
| return text.title() |
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 just_do_it(text): | |
| #Capitalize all words in <text> | |
| return text.capitalize() |
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
| F_BOIL_TEMP = 212.0 | |
| F_FREEZE_TEMP = 32.0 | |
| C_BOIL_TEMP = 100.0 | |
| C_FREEZE_TEMP = 0.0 | |
| F_RANGE = F_BOIL_TEMP - F_FREEZE_TEMP | |
| C_RANGE = C_BOIL_TEMP - C_FREEZE_TEMP | |
| F_C_RATIO = C_RANGE / F_RANGE | |
| def ftoc(f_temp): | |
| "Convfert Fahrenheit temprature<f_temp> into Celsius " |
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 zmq | |
| import string | |
| import time | |
| host = '127.0.0.1' | |
| port = 6789 | |
| ctx = zmq.Context() | |
| pub = ctx.socket(zmq.PUB) | |
| pub.bind('tcp://%s:%s' % (host, port)) |
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 redis | |
| import random | |
| from time import sleep | |
| conn = redis.Redis() | |
| chocolates = ['sweet', 'bitter', 'milk', 'white', 'green tea'] | |
| while True: | |
| sleep(random.random()) | |
| chocolate = random.choice(chocolates) | |
| conn.rpush('chocolates', chocolate) |
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 xmlrpc.server import SimpleXMLRPCServer | |
| from datetime import datetime | |
| def current_time(): | |
| now = str(datetime.now()) | |
| print('Server sent %s', now) | |
| return now | |
| server = SimpleXMLRPCServer(("localhost", 6789)) | |
| server.register_function(current_time, "current_time") |
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 zmq | |
| from datetime import datetime | |
| from time import sleep | |
| host = '127.0.0.1' | |
| port = 6789 | |
| context = zmq.Context() | |
| client = context.socket(zmq.REQ) | |
| client.connect("tcp://%s:%s" % (host, port)) | |
| print("Client started at %s" % datetime.now()) |