Skip to content

Instantly share code, notes, and snippets.

View Se7enSquared's full-sized avatar
🐍
import this

HGray Se7enSquared

🐍
import this
View GitHub Profile
@Se7enSquared
Se7enSquared / capslock_remap_alt.ahk
Created January 29, 2019 16:48 — forked from Danik/capslock_remap_alt.ahk
Autohotkey Capslock Remapping Script. Makes Capslock function as a modifier key to get cursor keys etc. on the left side of the keyboard, so you never have to move your hand to the right.
; 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
@Se7enSquared
Se7enSquared / convert2d.py
Last active October 18, 2019 20:35
Convert a nested (2D) list of lists into a single dimensional list
import itertools
a = [[1, 2], [3, 4], [5, 6]]
print(list(itertools.chain.from_iterable(a)))
# output: [1, 2, 3, 4, 5, 6]
@Se7enSquared
Se7enSquared / mapy.py
Last active October 18, 2019 20:36
MAP function - apply a function to every element in a list
# 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]
@Se7enSquared
Se7enSquared / zip_dict.py
Last active October 18, 2019 20:37
Interlace the key/values of a dictionary together
stocks = {
'Goog' : 520.54,
'FB' : 76.45,
'yhoo' : 39.28,
'AMZN' : 306.21,
'APPL' : 99.76
}
zipped_1 = zip(stocks.values(), stocks.keys())
@Se7enSquared
Se7enSquared / nlargest_nsmallest.py
Last active October 18, 2019 20:38
Find n largest / n smallest numbers in a list
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
@Se7enSquared
Se7enSquared / isanagram.py
Last active October 18, 2019 20:39
Check if two strings are anagrams (contain all the same letters in any order)
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
@Se7enSquared
Se7enSquared / freq_value.py
Last active October 18, 2019 21:48
Find the most frequently occuring item in a list
test = [1, 2, 3, 4, 2, 2, 3, 1, 4, 4, 4]
most_frequent - max(set(test), key = test.count)
# most_frequent = 4
@Se7enSquared
Se7enSquared / gen_frequency_table_for_column.py
Last active October 18, 2019 21:49
Generate frequency table for a column in list of lists
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]))
@Se7enSquared
Se7enSquared / strip_bad_chars.py
Last active October 18, 2019 21:50
Given a list of 'bad characters', iterate through that list and clean the data, removing said 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):
@Se7enSquared
Se7enSquared / set_of_column.py
Last active October 18, 2019 21:51
Get a set of items in a 'column' (specific row in a transposed list of lists)
column_2 = [[x[i] for x in my_list] for i in range(len(my_list[0]))]
print(set(column_2[2]))