def multipliers():
return [lambda x, i=i: i * x for i in range(4)]
print([m(2) for m in multipliers()]) # [0, 2, 4, 6]
def multipliers():
return (lambda x: i * x for i in range(4))
print([m(2) for m in multipliers()]) # [0, 2, 4, 6]
regexp = re.compile(ur'[а-яА-Яa-z-A-Z]+', re.UNICODE)
words = re.findall(regexp, str)
import io
import chardet
import os
import codecs
filename = 'test_file.txt'
bytes = min(32, os.path.getsize(filename))
raw = open(filename, 'rb').read(bytes)
if raw.startswith(codecs.BOM_UTF8):
encoding = 'utf-8-sig'
else:
result = chardet.detect(raw)
encoding = result['encoding']
infile = io.open(filename, 'r', encoding=encoding)
data = infile.read()
infile.close()
print(data)