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
; Autohotkey Capslock Remapping Script | |
; Danik | |
; More info at http://danikgames.com/blog/?p=714 | |
; danikgames.com | |
; | |
; Functionality: | |
; - Deactivates capslock for normal (accidental) use. | |
; - Hold Capslock and drag anywhere in a window to move it (not just the title bar). | |
; - Access the following functions when pressing Capslock: | |
; Cursor keys - J, K, L, I |
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
import itertools | |
a = [[1, 2], [3, 4], [5, 6]] | |
print(list(itertools.chain.from_iterable(a))) | |
# output: [1, 2, 3, 4, 5, 6] |
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
# Python code to apply a function on a list | |
income = [10, 30, 75] | |
def double_money(dollars): | |
return dollars * 2 | |
new_income = list(map(double_money, income)) | |
print(new_income) | |
# output: [20, 60, 150] |
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
stocks = { | |
'Goog' : 520.54, | |
'FB' : 76.45, | |
'yhoo' : 39.28, | |
'AMZN' : 306.21, | |
'APPL' : 99.76 | |
} | |
zipped_1 = zip(stocks.values(), stocks.keys()) |
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
import heapq | |
grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90] | |
print(heapq.nlargest(3, grades)) | |
# 110, 90, 87 | |
print(heapq.nsmallest(4, grades)) | |
# 25, 20, 33, 38 |
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
from collections import Counter | |
def is_anagram(str1, str2): | |
return Counter(str1) == Counter(str2) | |
print(is_anagram('geek', 'eegk')) | |
# True | |
print(is_anagram('geek', 'peek')) | |
# False |
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
test = [1, 2, 3, 4, 2, 2, 3, 1, 4, 4, 4] | |
most_frequent - max(set(test), key = test.count) | |
# most_frequent = 4 |
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
from collections import Counter | |
transposed_list = [[x[i] for x in my_list] for i in range(len(my_list[0]))] | |
col_freq = dict(Counter(transposed_list[col_num])) |
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
test_data = ["1912", "1929", "1913-1923", | |
"(1951)", "1994", "1934", | |
"c. 1915", "1995", "c. 1912", | |
"(1988)", "2002", "1957-1959", | |
"c. 1955.", "c. 1970's", | |
"C. 1990-1999"] | |
bad_chars = ["(",")","c","C",".","s","'", " "] | |
def strip_characters(string): |
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
column_2 = [[x[i] for x in my_list] for i in range(len(my_list[0]))] | |
print(set(column_2[2])) |
OlderNewer