PythonHost.ir | پایتون هاست
60 subscribers
51 photos
51 links
پایتون هاست | اولین و تنها میزبان تخصصی پروژه ها و ربات های پایتونی کشور

PythonHost.ir
Download Telegram
آموزش binary search با bisect #پایتون

import bisect
xs = [1, 3, 5, 7]
print(bisect.bisect_left(xs, 6))


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش Counter: پرتکرارترین‌ها #پایتون

from collections import Counter
print(Counter('aabccc').most_common(2))


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش deque برای sliding window #پایتون

from collections import deque
d = deque(maxlen=3)
for x in [1, 2, 3, 4]:
d.append(x)
print(list(d))


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش itertools: combinations #پایتون

import itertools
print(list(itertools.combinations([1, 2, 3, 4], 2)))


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش itertools: product #پایتون

import itertools
print(list(itertools.product([1, 2], ['a', 'b'])))


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش itertools: groupby پشت‌سرهم #پایتون

import itertools
s = 'aaabcc'
print([(k, len(list(g))) for k, g in itertools.groupby(s)])


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش argparse مینیمال #پایتون

import argparse
p = argparse.ArgumentParser()
p.add_argument('--n', type=int, default=3)
args = p.parse_args([])
print(args.n)


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش logging با فرمت #پایتون

import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
logging.info('ready')


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌
آموزش traceback تمیز #پایتون

import traceback
try:
1 / 0
except ZeroDivisionError:
print(traceback.format_exc().splitlines()[-1])


pythonhost.ir | پایتون هاست
@pythonhost_ir‌
‌