Last active
October 12, 2016 20:46
-
-
Save ClaudiuCreanga/e232791eb095879115533a13255ff5a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get max min of list | |
max(list) | |
min(list) | |
# sort a list | |
list.sort() | |
sorted(list) | |
# sort a list by a specific value | |
sorted(list, key = lambda x : x[2]) | |
# sort a dictionary by a specific value | |
sorted(dict.items(), key = lambda (x,y) : y["date"]) | |
sorted(dict.items(), key = lambda (x,y) : y["date"], reverse=True) # to return the reverse value | |
# get the even number from a list | |
filter(lambda x : x % 2 == 0, list) | |
# creates a dictionary with the number of times an item appears in a list i.e {'1': 1, '3': 2, '2': 1} | |
dict([i, myList.count(i)] for i in myList) | |
# concatenate sublists into a main list | |
concat_list = [j for i in myList for j in i] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment