3 Learn Python to A.I Programming – Lesson

3 Learn Python to A.I Programming – Lesson

1. zip() in Python –

zip() is a built-in Python function that pairs elements from two or more iterables (lists, tuples, etc.) into grouped tuples

[(1, 'a'), (2, 'b'), (3, 'c')]


[(10, 100, 1000), (20, 200, 2000), (30, 300, 3000)]


Alice is 24 years old
Bob is 30 years old
Charlie is 19 years old


zip() with index (compare to normal loop)

for i in range(len(names)):
print(names[i], ages[i])

for name, age in zip(names, ages):
print(name, age)


[(1, 'x'), (2, 'y')]

Because list b has only 2 elements.


Unzipping (reverse zip)

(1, 2, 3)
('a', 'b', 'c')


using AI with zip

Inputs: 0 0 Target: 0
Inputs: 0 1 Target: 0
Inputs: 1 0 Target: 0
Inputs: 1 1 Target: 1