PYTHON_SOLVES Telegram 44
## Сортировка и конвертация коллекций

Тема:
Как упорядочивать данные и менять тип коллекций.

numbers = [5, 2, 9, 1]

print(sorted(numbers))
# Вывод: [1, 2, 5, 9]

numbers.sort()
print(numbers)
# Вывод: [1, 2, 5, 9]

a = (1, 2, 3)
print(list(a))
# Вывод: [1, 2, 3]

b = [1, 2, 2, 3]
print(set(b))
# Вывод: {1, 2, 3}

person_ages = {"Аня":25, "Олег":30, "Ира":20}
sorted_keys = sorted(person_ages)
print(sorted_keys)
# Вывод: ['Аня', 'Ира', 'Олег']


Полезные советы:

* sorted() возвращает новый список, .sort() меняет исходный.
* Конвертация коллекций помогает удалить дубликаты и менять тип данных под задачу.
* Множества (set) удобны для проверки уникальности элементов.

#азы



tgoop.com/python_solves/44
Create:
Last Update:

## Сортировка и конвертация коллекций

Тема:
Как упорядочивать данные и менять тип коллекций.

numbers = [5, 2, 9, 1]

print(sorted(numbers))
# Вывод: [1, 2, 5, 9]

numbers.sort()
print(numbers)
# Вывод: [1, 2, 5, 9]

a = (1, 2, 3)
print(list(a))
# Вывод: [1, 2, 3]

b = [1, 2, 2, 3]
print(set(b))
# Вывод: {1, 2, 3}

person_ages = {"Аня":25, "Олег":30, "Ира":20}
sorted_keys = sorted(person_ages)
print(sorted_keys)
# Вывод: ['Аня', 'Ира', 'Олег']


Полезные советы:

* sorted() возвращает новый список, .sort() меняет исходный.
* Конвертация коллекций помогает удалить дубликаты и менять тип данных под задачу.
* Множества (set) удобны для проверки уникальности элементов.

#азы

BY Python решает 🐍


Share with your friend now:
tgoop.com/python_solves/44

View MORE
Open in Telegram


Telegram News

Date: |

Hashtags are a fast way to find the correct information on social media. To put your content out there, be sure to add hashtags to each post. We have two intelligent tips to give you: Polls Just as the Bitcoin turmoil continues, crypto traders have taken to Telegram to voice their feelings. Crypto investors can reduce their anxiety about losses by joining the “Bear Market Screaming Therapy Group” on Telegram. As of Thursday, the SUCK Channel had 34,146 subscribers, with only one message dated August 28, 2020. It was an announcement stating that police had removed all posts on the channel because its content “contravenes the laws of Hong Kong.” Other crimes that the SUCK Channel incited under Ng’s watch included using corrosive chemicals to make explosives and causing grievous bodily harm with intent. The court also found Ng responsible for calling on people to assist protesters who clashed violently with police at several universities in November 2019.
from us


Telegram Python решает 🐍
FROM American