update lint

This commit is contained in:
Rohit Tanwar
2018-01-16 18:35:58 +05:30
parent 01077dcf5c
commit 81a5dc868c
10 changed files with 32 additions and 24 deletions

View File

@ -5,7 +5,7 @@ python:
install: install:
pip install -r requirements.txt pip install -r requirements.txt
script: script:
- python scripts/pretty.py - python scripts/lint.py
- python scripts/readme.py - python scripts/readme.py
after_success: after_success:
- chmod +x .travis/push.sh - chmod +x .travis/push.sh

View File

@ -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`. Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `arr`.
```python ```python
from math import ceil from math import ceil
@ -27,14 +29,16 @@ def chunk(arr, size):
chunk([1,2,3,4,5],2) # [[1,2],[3,4],5] chunk([1,2,3,4,5],2) # [[1,2],[3,4],5]
``` ```
### countOccurences ### count_occurences
Counts the occurrences of a value in an list. 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. Uses the `reduce` functin from built-in module `functools` to increment a counter each time you encounter the specific value inside the list.
```python ```python
def countOccurences(arr, val):
def count_occurences(arr, val):
return reduce( return reduce(
(lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0), (lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0),
arr) arr)
@ -42,26 +46,28 @@ def countOccurences(arr, val):
``` ```
```python ```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`. 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. Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a string.
```python ```python
import re import re
def countVowels(str): def count_vowels(str):
return len(len(re.findall(r'[aeiou]', str, re.IGNORECASE))) return len(len(re.findall(r'[aeiou]', str, re.IGNORECASE)))
``` ```
``` python ``` python
countVowels('foobar') # 3 count_vowels('foobar') # 3
countVowels('gym') # 0 count_vowels('gym') # 0
``` ```
### gcd ### 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. Uses the reduce function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists.
```python ```python
from functools import reduce 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. Uses `reduce` function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists.
```python ```python
from functools import reduce 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. Implements javascript's spread syntax as a function. Flattens the list(non-deep) and returns an list.
```python ```python
def spread(arg): def spread(arg):
ret = [] ret = []
for i in arg: for i in arg:

View File

@ -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()

View File

@ -1,6 +1,5 @@
import os import os
files = os.listdir('snippets') files = os.listdir('snippets')
print(os.listdir())
start = open("static-parts/readme-start.md").read() + '\n\n' start = open("static-parts/readme-start.md").read() + '\n\n'
end = open("static-parts/readme-end.md").read() end = open("static-parts/readme-end.md").read()
toAppend = '' toAppend = ''

View File

@ -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`. Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `arr`.
```python ```python
from math import ceil from math import ceil

View File

@ -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. Uses the `reduce` functin from built-in module `functools` to increment a counter each time you encounter the specific value inside the list.
```python ```python
def count_occurences(arr, val): def count_occurences(arr, val):
return reduce( return reduce(
(lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0), (lambda x, y: x + 1 if y == val and type(y) == type(val) else x + 0),

View File

@ -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. Use a regular expression to count the number of vowels `(A, E, I, O, U)` in a string.
```python ```python
import re import re

View File

@ -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. Uses the reduce function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists.
```python ```python
from functools import reduce from functools import reduce

View File

@ -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. Uses `reduce` function from the inbuilt module `functools`. Also defines a method `spread` for javascript like spreading of lists.
```python ```python
from functools import reduce from functools import reduce

View File

@ -3,6 +3,8 @@
Implements javascript's spread syntax as a function. Flattens the list(non-deep) and returns an list. Implements javascript's spread syntax as a function. Flattens the list(non-deep) and returns an list.
```python ```python
def spread(arg): def spread(arg):
ret = [] ret = []
for i in arg: for i in arg: