🐍 Python & Raspberry 🐍
8.21K subscribers
1.92K photos
125 videos
623 files
1.23K links
Python- Raspberry Pi-AI-IOT
ادمین : فرهاد ناصری زاده
@farhad_naserizadeh
@farhad3412

گروه پایتون
@Python_QA
تبادل
@mmtahmasbi
کانال مرتبط
@new_mathematical
@micropython_iot
@c_micro
اینستاگرام
http://Instagram.com/python_raspberry
Download Telegram
#آموزش 3 📚
#Itertools
ماژول itertools در پایتون :

این ماژول تمام ترکیبات ممکن k تایی در یک لیست را نشان می دهد.

در مثال زیر k=2 می باشد.

import itertools
a = [1,2,3,4,5]
b = list(itertools.combinations(a, 2))
print(b)

Output:

[(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)]

اگر k=3 باشد داریم :
import itertools
a = [1,2,3,4,5]
b = list(itertools.combinations(a, 3))
print(b)

Output:

[(1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 4),
(1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5),
(2, 4, 5), (3, 4, 5)]

@raspberry_python