Hidden Treasures - Core Python by Mayank Johri & Mayank Johri

Hidden Treasures - Core Python by Mayank Johri & Mayank Johri

Author:Mayank Johri & Mayank Johri [Johri, Mayank]
Language: eng
Format: azw3
Publisher: GitBook
Published: 2018-02-24T16:00:00+00:00


Deepcopy a list

ori = [1, 2, 3, 4, 5, 6] dup = ori[:] print(id(ori)) print(id(dup))

140307524228424 140307524230408

dup.insert(0, 29) print(ori) print(dup)

[1, 2, 3, 4, 5, 6] [29, 1, 2, 3, 4, 5, 6]

Most common elements in an iterable

ori = [1, 2, 3, 3, 4, 5, 5, 4, 5, 6, 4, 5, 6, ] from collections import Counter counter = Counter(ori) print(counter.most_common())

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

Dictionaries

converting dictionry keys to tuple

tuple({'aa': 0, 'bb': 1, 'cc': 2, 'dd': 3, 'ee': 4})

('aa', 'bb', 'cc', 'dd', 'ee')



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.