diff --git a/Closure/html_closure.js b/Closure/html_closure.js new file mode 100644 index 000000000..fe711f984 --- /dev/null +++ b/Closure/html_closure.js @@ -0,0 +1,10 @@ +function html_tag(tag) { + function print_tag(text) { + return '<'+tag+'>'+text+'' + }; + return print_tag +}; + +h1_tag = html_tag('h1') + +console.log(h1_tag('This is a Headline!')) \ No newline at end of file diff --git a/Closure/html_closure.py b/Closure/html_closure.py new file mode 100644 index 000000000..02bc90f8e --- /dev/null +++ b/Closure/html_closure.py @@ -0,0 +1,21 @@ +def outer(): + x = 10 + def inner(): + y = 20 + inner() + return x + y + +my_func = outer + +print my_func() + +# h1_tag = html_tag('h1') +# print h1_tag + +# def html_tag(tag): +# def print_tag(text): +# return '<{0}>{1}'.format(tag,text) +# return print_tag + +# h1_tag = html_tag('h1') +# print h1_tag('This is a headline!') diff --git a/Combinations-Permutations/comb_perm.py b/Combinations-Permutations/comb_perm.py new file mode 100644 index 000000000..7a22395f3 --- /dev/null +++ b/Combinations-Permutations/comb_perm.py @@ -0,0 +1,11 @@ +import itertools + +my_list = [1,2,3] + +# combinations = itertools.combinations(my_list, 2) +# for c in combinations: +# print c + +permutations = itertools.permutations(my_list, 2) +for p in permutations: + print p \ No newline at end of file diff --git a/Combinations-Permutations/examples.py b/Combinations-Permutations/examples.py new file mode 100644 index 000000000..3a23b0e63 --- /dev/null +++ b/Combinations-Permutations/examples.py @@ -0,0 +1,22 @@ +import itertools + +# my_list = [1,2,3,4,5,6] + +# combinations = itertools.combinations(my_list, 3) +# permutations = itertools.permutations(my_list, 3) + +# print [result for result in combinations if sum(result) == 10] + +word = 'sample' +my_letters = 'plmeas' + +combinations = itertools.combinations(my_letters, 6) +permutations = itertools.permutations(my_letters, 6) + +for p in permutations: + # print p + if ''.join(p) == word: + print 'Match!' + break +else: + print 'No Match!' \ No newline at end of file diff --git a/FC_Functions/fc_functions.py b/FC_Functions/fc_functions.py new file mode 100644 index 000000000..5d01519a1 --- /dev/null +++ b/FC_Functions/fc_functions.py @@ -0,0 +1,14 @@ + +def html_tag(tag): + + def wrap_text(msg): + print('<{0}>{1}'.format(tag, msg)) + + return wrap_text + +print_h1 = html_tag('h1') +print_h1('Test Headline!') +print_h1('Another Headline!') + +print_p = html_tag('p') +print_p('Test Paragraph!') diff --git a/Idempotence/methods.txt b/Idempotence/methods.txt new file mode 100644 index 000000000..0ebc01d91 --- /dev/null +++ b/Idempotence/methods.txt @@ -0,0 +1,6 @@ +HTTP METHODS + +GET /users/123 +PUT +POST +DELETE \ No newline at end of file diff --git a/Idempotence/test.py b/Idempotence/test.py new file mode 100644 index 000000000..5361a6600 --- /dev/null +++ b/Idempotence/test.py @@ -0,0 +1,15 @@ +# f(x) +# add_ten(num) +def add_ten(num): + return num + 10 + +# f(f(x)) = f(x) +# f(f(10)) = 30 | f(10) = 20 +# print add_ten(add_ten(10)) + +print abs(abs(abs(-10))) +# abs(-10) == 10 +# abs(10) == 10 +# abs(10) == 10 + +a = 10 \ No newline at end of file diff --git a/Memoization/sample.py b/Memoization/sample.py new file mode 100644 index 000000000..1e4a483a3 --- /dev/null +++ b/Memoization/sample.py @@ -0,0 +1,25 @@ +import time + +ef_cache = {} + +def expensive_func(num): + if num in ef_cache: + return ef_cache[num] + + print "Computing {}...".format(num) + time.sleep(1) + result = num*num + ef_cache[num] = result + return result + +result = expensive_func(4) +print result + +result = expensive_func(10) +print result + +result = expensive_func(4) +print result + +result = expensive_func(10) +print result \ No newline at end of file diff --git a/Mutable/code.py b/Mutable/code.py new file mode 100644 index 000000000..f30c2ee71 --- /dev/null +++ b/Mutable/code.py @@ -0,0 +1,6 @@ + +print 'Address of a is: {}'.format(id(a)) + +# a[0] = '' +# print a +# print 'Address of a is: {}'.format(id(a)) \ No newline at end of file diff --git a/Mutable/concat.py b/Mutable/concat.py new file mode 100644 index 000000000..a791d9e8e --- /dev/null +++ b/Mutable/concat.py @@ -0,0 +1,14 @@ + +employees = ['Corey', 'John', 'Rick', 'Steve', 'Carl', 'Adam'] + +output = '' + +print output + +print '\n' \ No newline at end of file diff --git a/Mutable/mutable.py b/Mutable/mutable.py new file mode 100644 index 000000000..29fc33ed7 --- /dev/null +++ b/Mutable/mutable.py @@ -0,0 +1,8 @@ + +a = [1,2,3,4,5] +print a +print 'Address of a is: {}'.format(id(a)) + +a[0] = 6 +print a +print 'Address of a is: {}'.format(id(a)) \ No newline at end of file diff --git a/String Interpolation/test.py b/String Interpolation/test.py new file mode 100644 index 000000000..4162dd97d --- /dev/null +++ b/String Interpolation/test.py @@ -0,0 +1,9 @@ +name = 'Corey' +age = 28 + +# greeting = 'My name is ' + name + ' and I am ' + str(age) + ' years old' + +greeting = 'I am {age} years old and my name is {name}'.format(name=name, age=age) + +print greeting +