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
lst = ['a', 'a', 'a'] | |
print(len(set(lst)) == 1) | |
# True | |
print(all((x == lst[0]) for x in lst)) | |
# True | |
print(lst.count(lst[0]) == len(lst)) | |
# True |
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
import asyncio | |
f = asyncio.coroutine(lambda x: x**2) | |
asyncio.get_event_loop().run_until_complete(f(12)) | |
# 144 |
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
# -*- coding: utf-8 -*- | |
eng = ['one', 'two', 'three'] | |
ger = ['eins', 'zwei', 'drei'] | |
rus = ['один', 'два', 'три'] | |
for e, g, r in zip(eng, ger, rus): | |
print('{e} = {g} = {r}'.format(e=e, g=g, r=r)) | |
# one = eins = один |
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
# -*- coding: utf-8 -*- | |
import math | |
π = math.pi | |
print(π) | |
# 3.141592653589793 | |
τ = math.tau |
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
# -*- coding: utf-8 -*- | |
# pip install pyautogui | |
import pyautogui | |
screen = pyautogui.screenshot('screenshot.png') | |
# region_screen = pyautogui.screenshot('region_screenshot.png', region=(0, 0, 300, 400)) |
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
# -*- coding: utf-8 -*- | |
from itertools import permutations, combinations, chain | |
for p in permutations([1, 2, 3]): | |
print(p) | |
# (1, 2, 3) | |
# (1, 3, 2) | |
# (2, 1, 3) |
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
# -*- coding: utf-8 -*- | |
def fib(n): | |
if n < 2: | |
return 1 | |
return fib(n-1) + fib(n-2) | |
print(fib(6)) |
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
# -*- coding: utf-8 -*- | |
nums = [str(n) for n in range(10)] | |
print("".join(nums)) | |
# 0123456789 | |
foo = 'foo' | |
bar = 'bar' | |
foobar = '{foo}{bar}'.format(foo=foo, bar=bar) |
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
# -*- coding: utf-8 -*- | |
name = 'User' | |
f'Hello, {name}!' | |
#'Hello, User!' | |
# most powerfull part is | |
a = 10 | |
b = 4 | |
f'Ten plus four is {a + b}' |
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
# -*- coding: utf-8 -*- | |
def hello(name, question): | |
return f"Hello, {name},! How is it {question}?" | |
hello('Stranger', 'going') | |
#"Hello, Stranger! How is it going?" | |
# Similar approach | |
# def hello(name, question): |
OlderNewer