diff --git a/.travis.yml b/.travis.yml index 7b04e8d0a..a16d4f863 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: install: pip install -r requirements.txt script: -- python scripts/pretty.py +- python scripts/lint.py - python scripts/readme.py after_success: - chmod +x .travis/push.sh diff --git a/README.md b/README.md index cb9162487..742e5d7cd 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Chunks an array into smaller lists of a specified size. Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `arr`. ```python + + from math import ceil @@ -27,14 +29,16 @@ def chunk(arr, size): chunk([1,2,3,4,5],2) # [[1,2],[3,4],5] ``` -### countOccurences +### count_occurences Counts the occurrences of a value in an list. Uses the `reduce` functin from built-in module `functools` to increment a counter each time you encounter the specific value inside the list. ```python -def countOccurences(arr, val): + + +def count_occurences(arr, val): return reduce( (lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0), arr) @@ -42,26 +46,28 @@ def countOccurences(arr, val): ``` ```python -countOccurrences([1, 1, 2, 1, 2, 3], 1) # 3 +count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3 ``` -### countVowels +### count_vowels Retuns `number` of vowels in provided `string`. Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a string. ```python + + import re -def countVowels(str): +def count_vowels(str): return len(len(re.findall(r'[aeiou]', str, re.IGNORECASE))) ``` ``` python -countVowels('foobar') # 3 -countVowels('gym') # 0 +count_vowels('foobar') # 3 +count_vowels('gym') # 0 ``` ### gcd @@ -73,6 +79,8 @@ The `helperGcdfunction` uses recursion. Base case is when `y` equals `0`. In thi Uses the reduce function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists. ```python + + from functools import reduce @@ -110,6 +118,8 @@ Use the `greatest common divisor (GCD)` formula and the fact that `lcm(x,y) = x Uses `reduce` function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists. ```python + + from functools import reduce @@ -147,6 +157,8 @@ lcm([1, 3, 4], 5) # 60 Implements javascript's spread syntax as a function. Flattens the list(non-deep) and returns an list. ```python + + def spread(arg): ret = [] for i in arg: diff --git a/scripts/pretty.py b/scripts/pretty.py deleted file mode 100644 index c3c4daad6..000000000 --- a/scripts/pretty.py +++ /dev/null @@ -1,15 +0,0 @@ -import autopep8 -import re -import os -files = os.listdir('snippets') -codeRe = "```\s*python([\s\S]*?)```" -for file in files: - someFile = open("snippets/" + file) - fileData = someFile.read() - someFile.close() - originalCode = re.search(codeRe,fileData).group(0) - formatedCode = autopep8.fix_code(re.split(codeRe,fileData)[1]) - fileToSave = fileData.replace(originalCode,('```python \n'+formatedCode[0]+'\n```')) - someFile = open("snippets/"+file,'w') - someFile.write(fileToSave) - someFile.close() \ No newline at end of file diff --git a/scripts/readme.py b/scripts/readme.py index 915c808d3..dfe2058e3 100644 --- a/scripts/readme.py +++ b/scripts/readme.py @@ -1,6 +1,5 @@ import os files = os.listdir('snippets') -print(os.listdir()) start = open("static-parts/readme-start.md").read() + '\n\n' end = open("static-parts/readme-end.md").read() toAppend = '' diff --git a/snippets/chunk.md b/snippets/chunk.md index 356cc6c54..f6f180acb 100644 --- a/snippets/chunk.md +++ b/snippets/chunk.md @@ -5,6 +5,8 @@ Chunks an array into smaller lists of a specified size. Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `arr`. ```python + + from math import ceil diff --git a/snippets/count_occurences.md b/snippets/count_occurences.md index a8307b86d..8dd324e15 100644 --- a/snippets/count_occurences.md +++ b/snippets/count_occurences.md @@ -5,6 +5,8 @@ Counts the occurrences of a value in an list. Uses the `reduce` functin from built-in module `functools` to increment a counter each time you encounter the specific value inside the list. ```python + + def count_occurences(arr, val): return reduce( (lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0), diff --git a/snippets/count_vowels.md b/snippets/count_vowels.md index 134fbe2f4..87b0fbb47 100644 --- a/snippets/count_vowels.md +++ b/snippets/count_vowels.md @@ -5,6 +5,8 @@ Retuns `number` of vowels in provided `string`. Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a string. ```python + + import re diff --git a/snippets/gcd.md b/snippets/gcd.md index f9fca6635..595551859 100644 --- a/snippets/gcd.md +++ b/snippets/gcd.md @@ -7,6 +7,8 @@ The `helperGcdfunction` uses recursion. Base case is when `y` equals `0`. In thi Uses the reduce function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists. ```python + + from functools import reduce diff --git a/snippets/lcm.md b/snippets/lcm.md index f4df6bbbb..d0d7c0703 100644 --- a/snippets/lcm.md +++ b/snippets/lcm.md @@ -7,6 +7,8 @@ Use the `greatest common divisor (GCD)` formula and the fact that `lcm(x,y) = x Uses `reduce` function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists. ```python + + from functools import reduce diff --git a/snippets/spread.md b/snippets/spread.md index a0e4e1148..cc33d47e9 100644 --- a/snippets/spread.md +++ b/snippets/spread.md @@ -3,6 +3,8 @@ Implements javascript's spread syntax as a function. Flattens the list(non-deep) and returns an list. ```python + + def spread(arg): ret = [] for i in arg: