Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
22 lines (22 loc) · 957 Bytes

File metadata and controls

22 lines (22 loc) · 957 Bytes
Copy raw file
Download raw file
Outline
Edit and raw actions

Top line Python improving

Module specific

Timedelta

timedelta seconds only go up to one day. Uses solely days and seconds internally

Collections module

from collections import defaultdict, namedtuple, Counter, deque

namedtuple, kinda like a dictionary. Sotre stuff with a default set of tags

User = namedtuple(‘User’, ‘name role’) user = User(name=’bob’, role=’coder’) call with user.role

Default dic if you want to append/edit data to your names members on the fly

challenges_done = [(‘mike’, 10), (‘julian’, 7), (‘bob’, 5), (‘mike’, 11), (‘julian’, 8), (‘bob’, 6)] challenges = defaultdict(list) for name, challenge in challenges_done: challenges[name].append(challenge)

Counter, v simple

Counter(words).most_common(5)

Deque is like a list but faster operating with adding and removing mid list

Cool stuff standard modules

%timeit to time chunks of code Counter to efficiently count instances of stuff

Morty Proxy This is a proxified and sanitized view of the page, visit original site.