Python zip()

Configurare noua (How To)

Situatie

The zip() function takes iterables (can be zero or more), aggregates them in a tuple, and returns it.

Solutie

Pasi de urmat

number_list = [1, 2, 3]
str_list = [‘one’, ‘two’, ‘three’]

# No iterables are passed
result = zip()

# Converting iterator to list
result_list = list(result)
print(result_list)

# Two iterables are passed
result = zip(number_list, str_list)

# Converting iterator to set
result_set = set(result)
print(result_set)

Output:

[]
{(2, ‘two’), (3, ‘three’), (1, ‘one’)}

Tip solutie

Permanent

Voteaza

(5 din 14 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?