GeezerVison is showing github.com — Added Term snippets · pcblanchet/code_snippets@34653e5
File treeExpand file treeCollapse file tree Open diff view settings Combinations-Permutations
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +function html_tag(tag) { | | 2 | + function print_tag(text) { | | 3 | + return '<'+tag+'>'+text+'</'+tag+'>' | | 4 | + }; | | 5 | + return print_tag | | 6 | +}; | | 7 | + | | 8 | +h1_tag = html_tag('h1') | | 9 | + | | 10 | +console.log(h1_tag('This is a Headline!')) |
Collapse file Copy file name to clipboard +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +def outer(): | | 2 | + x = 10 | | 3 | + def inner(): | | 4 | + y = 20 | | 5 | + inner() | | 6 | + return x + y | | 7 | + | | 8 | +my_func = outer | | 9 | + | | 10 | +print my_func() | | 11 | + | | 12 | +# h1_tag = html_tag('h1') | | 13 | +# print h1_tag | | 14 | + | | 15 | +# def html_tag(tag): | | 16 | +# def print_tag(text): | | 17 | +# return '<{0}>{1}</{0}>'.format(tag,text) | | 18 | +# return print_tag | | 19 | + | | 20 | +# h1_tag = html_tag('h1') | | 21 | +# print h1_tag('This is a headline!') |
Collapse file Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import itertools | | 2 | + | | 3 | +my_list = [1,2,3] | | 4 | + | | 5 | +# combinations = itertools.combinations(my_list, 2) | | 6 | +# for c in combinations: | | 7 | +# print c | | 8 | + | | 9 | +permutations = itertools.permutations(my_list, 2) | | 10 | +for p in permutations: | | 11 | + print p |
Collapse file Copy file name to clipboard +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import itertools | | 2 | + | | 3 | +# my_list = [1,2,3,4,5,6] | | 4 | + | | 5 | +# combinations = itertools.combinations(my_list, 3) | | 6 | +# permutations = itertools.permutations(my_list, 3) | | 7 | + | | 8 | +# print [result for result in combinations if sum(result) == 10] | | 9 | + | | 10 | +word = 'sample' | | 11 | +my_letters = 'plmeas' | | 12 | + | | 13 | +combinations = itertools.combinations(my_letters, 6) | | 14 | +permutations = itertools.permutations(my_letters, 6) | | 15 | + | | 16 | +for p in permutations: | | 17 | + # print p | | 18 | + if ''.join(p) == word: | | 19 | + print 'Match!' | | 20 | + break | | 21 | +else: | | 22 | + print 'No Match!' |
Collapse file Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | + | | 2 | +def html_tag(tag): | | 3 | + | | 4 | + def wrap_text(msg): | | 5 | + print('<{0}>{1}</{0}>'.format(tag, msg)) | | 6 | + | | 7 | + return wrap_text | | 8 | + | | 9 | +print_h1 = html_tag('h1') | | 10 | +print_h1('Test Headline!') | | 11 | +print_h1('Another Headline!') | | 12 | + | | 13 | +print_p = html_tag('p') | | 14 | +print_p('Test Paragraph!') |
Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +HTTP METHODS | | 2 | + | | 3 | +GET <url>/users/123 | | 4 | +PUT | | 5 | +POST | | 6 | +DELETE |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# f(x) | | 2 | +# add_ten(num) | | 3 | +def add_ten(num): | | 4 | + return num + 10 | | 5 | + | | 6 | +# f(f(x)) = f(x) | | 7 | +# f(f(10)) = 30 | f(10) = 20 | | 8 | +# print add_ten(add_ten(10)) | | 9 | + | | 10 | +print abs(abs(abs(-10))) | | 11 | +# abs(-10) == 10 | | 12 | +# abs(10) == 10 | | 13 | +# abs(10) == 10 | | 14 | + | | 15 | +a = 10 |
Collapse file Copy file name to clipboard +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import time | | 2 | + | | 3 | +ef_cache = {} | | 4 | + | | 5 | +def expensive_func(num): | | 6 | + if num in ef_cache: | | 7 | + return ef_cache[num] | | 8 | + | | 9 | + print "Computing {}...".format(num) | | 10 | + time.sleep(1) | | 11 | + result = num*num | | 12 | + ef_cache[num] = result | | 13 | + return result | | 14 | + | | 15 | +result = expensive_func(4) | | 16 | +print result | | 17 | + | | 18 | +result = expensive_func(10) | | 19 | +print result | | 20 | + | | 21 | +result = expensive_func(4) | | 22 | +print result | | 23 | + | | 24 | +result = expensive_func(10) | | 25 | +print result |
Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | + | | 2 | +print 'Address of a is: {}'.format(id(a)) | | 3 | + | | 4 | +# a[0] = '' | | 5 | +# print a | | 6 | +# print 'Address of a is: {}'.format(id(a)) |
Collapse file Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | + | | 2 | +employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam'] | | 3 | + | | 4 | +output = '<ul>\n' | | 5 | + | | 6 | +for employee in employees: | | 7 | + output += '\t<li>{}</li>\n'.format(employee) | | 8 | + print 'Address of output is {}'.format(id(output)) | | 9 | + | | 10 | +output += '</ul>' | | 11 | + | | 12 | +print output | | 13 | + | | 14 | +print '\n' |
|