diff --git a/contributor_database b/contributor_database deleted file mode 100644 index 05959e651..000000000 --- a/contributor_database +++ /dev/null @@ -1,32 +0,0 @@ -average:[Rohit Tanwar](@kriadmin),[Hui Binyuan](@huybery) -chunk:[Rohit Tanwar](@kriadmin) -compact:[Rohit Tanwar](@kriadmin) -count_occurences:[Rohit Tanwar](@kriadmin), [Hui Binyuan](@huybery) -count_vowels:[Rohit Tanwar](@kriadmin) -deep_flatten:[Rohit Tanwar](@kriadmin),[Meet Zaveri](@meetzaveri) -difference:[Rohit Tanwar](@kriadmin) -factorial:[Rohit Tanwar](@kriadmin) -gcd:[Rohit Tanwar](@kriadmin),[cclauss](@cclauss),[Sandhya Saravanan](@sandy9999) -lcm:[Rohit Tanwar](@kriadmin) -max_n:[Rohit Tanwar](@kriadmin) -min_n:[Rohit Tanwar](@kriadmin) -shuffle:[Rohit Tanwar](@kriadmin) -spread:[Rohit Tanwar](@kriadmin) -zip:[Rohit Tanwar](@kriadmin),[Leonardo Galdino](@LeonardoGaldino) -byte_size:[Rohit Tanwar](@kriadmin) -capitalize:[Rohit Tanwar](@kriadmin) -capitalize_every_word:[Rohit Tanwar](@kriadmin) -decapitalize:[Rohit Tanwar](@kriadmin) -palindrome:[Rohit Tanwar](@kriadmin) -is_upper_case:[Rohit Tanwar](@kriadmin) -is_lower_case:[Rohit Tanwar](@kriadmin) -count_by:[Rohit Tanwar](@kriadmin) -insertion_sort:[Meet Zaveri](@meetzaveri),[Rohit Tanwar](@kriadmin) -difference_by:[Rohit Tanwar](@kriadmin) -bubble_sort: [Shobhit Sachan](@sachans) -has_duplicates: [Rob-Rychs](@Rob-Rychs) -keys_only: [Rob-Rychs](@Rob-Rychs),[Matteo Veraldi](@mattveraldi) -values_only: [Rob-Rychs](@Rob-Rychs) -all_unique: [Rob-Rychs](@Rob-Rychs) -fibonacci_until_num: [Nian Lee](@scraggard) -fermat_test: [Alexander Pozdniakov](@0awawa0) diff --git a/snippet_template.md b/snippet_template.md index e22cbb072..b034ae5a4 100644 --- a/snippet_template.md +++ b/snippet_template.md @@ -1,15 +1,18 @@ -### function_name +--- +title: function_name +tags: +--- -Describe briefly what the function does +Explain briefly what the snippet does. -Explain your method and the functions used. +Explain briefly how the snippet works. ``` python def function_name(args): - # code - return 0 + # code + return 0 ``` ``` python -function_name(val) # result +functionName(val) # result ``` diff --git a/snippets/all_unique.md b/snippets/all_unique.md index ea4177beb..5f161525b 100644 --- a/snippets/all_unique.md +++ b/snippets/all_unique.md @@ -1,5 +1,7 @@ -### all_unique - +--- +title: all_unique +tags: list +--- Checks a flat list for all unique values. Returns True if list values are all unique and False if list values aren't all unique. This function compares the length of the list with length of the set() of the list. set() removes duplicate values from the list. diff --git a/snippets/average.md b/snippets/average.md index a067ae6cb..0b18b501b 100644 --- a/snippets/average.md +++ b/snippets/average.md @@ -1,5 +1,7 @@ -### average - +--- +title: average +tags: math +--- :information_source: Already implemented via `statistics.mean`. `statistics.mean` takes an array as an argument whereas this function takes variadic arguments. Returns the average of two or more numbers. diff --git a/snippets/bubble_sort.md b/snippets/bubble_sort.md index 281d5e554..292b0a2e7 100644 --- a/snippets/bubble_sort.md +++ b/snippets/bubble_sort.md @@ -1,4 +1,8 @@ -### bubble_sort +--- +title: bubble_sort +tags: list +--- + Bubble_sort uses the technique of comparing and swapping ```python diff --git a/snippets/byte_size.md b/snippets/byte_size.md index 7f34b08df..73e64b2a6 100644 --- a/snippets/byte_size.md +++ b/snippets/byte_size.md @@ -1,5 +1,7 @@ -### byte_size - +--- +title: byte_size +tags: string +--- Returns the length of a string in bytes. `utf-8` encodes a given string, then `len` finds the length of the encoded string. diff --git a/snippets/capitalize.md b/snippets/capitalize.md index b685afc5c..52c8e1f25 100644 --- a/snippets/capitalize.md +++ b/snippets/capitalize.md @@ -1,5 +1,7 @@ -### capitalize - +--- +title: capitalize +tags: string +--- Capitalizes the first letter of a string. Capitalizes the first letter of the string and then adds it with rest of the string. Omit the `lower_rest` parameter to keep the rest of the string intact, or set it to `true` to convert to lowercase. diff --git a/snippets/capitalize_every_word.md b/snippets/capitalize_every_word.md index 86f5c3a5f..3c9882206 100644 --- a/snippets/capitalize_every_word.md +++ b/snippets/capitalize_every_word.md @@ -1,5 +1,7 @@ -### capitalize_every_word - +--- +title: capitalize_every_word +tags: string +--- Capitalizes the first letter of every word in a string. Uses `str.title` to capitalize first letter of every word in the string. diff --git a/snippets/chunk.md b/snippets/chunk.md index 825e602a3..c80662acf 100644 --- a/snippets/chunk.md +++ b/snippets/chunk.md @@ -1,5 +1,7 @@ -### chunk - +--- +title: chunk +tags: list +--- Chunks an list 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 `lst`. diff --git a/snippets/compact.md b/snippets/compact.md index 1d1767512..64aff2941 100644 --- a/snippets/compact.md +++ b/snippets/compact.md @@ -1,5 +1,7 @@ -### compact - +--- +title: compact +tags: list +--- Removes falsey values from a list. Use `filter()` to filter out falsey values (False, None, 0, and ""). diff --git a/snippets/count_by.md b/snippets/count_by.md index a20dde7a0..beb29f8ca 100644 --- a/snippets/count_by.md +++ b/snippets/count_by.md @@ -1,5 +1,7 @@ -### count_by - +--- +title: count_by +tags: list +--- :information_source: Already implemented via `collections.Counter` Groups the elements of a list based on the given function and returns the count of elements in each group. diff --git a/snippets/count_occurences.md b/snippets/count_occurences.md index 7a3c930e7..7db32d840 100644 --- a/snippets/count_occurences.md +++ b/snippets/count_occurences.md @@ -1,5 +1,7 @@ -### count_occurences - +--- +title: count_occurences +tags: list +--- :information_source: Already implemented via `list.count()`. Counts the occurrences of a value in a list. diff --git a/snippets/count_vowels.md b/snippets/count_vowels.md index dc34acffe..4029ea98c 100644 --- a/snippets/count_vowels.md +++ b/snippets/count_vowels.md @@ -1,5 +1,7 @@ -### count_vowels - +--- +title: count_vowels +tags: 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. diff --git a/snippets/decapitalize.md b/snippets/decapitalize.md index 9f40f22ef..a506fa5fa 100644 --- a/snippets/decapitalize.md +++ b/snippets/decapitalize.md @@ -1,5 +1,7 @@ -### decapitalize - +--- +title: decapitalize +tags: string +--- Decapitalizes the first letter of a string. Decapitalizes the first letter of the string and then adds it with rest of the string. Omit the `upper_rest` parameter to keep the rest of the string intact, or set it to `true` to convert to uppercase. diff --git a/snippets/deep_flatten.md b/snippets/deep_flatten.md index cfbf6591d..87860aff3 100644 --- a/snippets/deep_flatten.md +++ b/snippets/deep_flatten.md @@ -1,5 +1,7 @@ -### deep_flatten - +--- +title: deep_flatten +tags: list +--- Deep flattens a list. Use recursion. Use `list.extend()` with an empty list (`result`) and the spread function to flatten a list. Recursively flatten each element that is a list. diff --git a/snippets/difference.md b/snippets/difference.md index 21d09c5c1..b19b063c5 100644 --- a/snippets/difference.md +++ b/snippets/difference.md @@ -1,5 +1,7 @@ -### difference - +--- +title: difference +tags: list +--- Returns the difference between two iterables. Use list comprehension to only keep values not contained in `b`. diff --git a/snippets/difference_by.md b/snippets/difference_by.md index 5fcd004a2..96ce12e08 100644 --- a/snippets/difference_by.md +++ b/snippets/difference_by.md @@ -1,5 +1,7 @@ -### difference_by - +--- +title: difference_by +tags: list +--- Returns the difference between two list, after applying the provided function to each list element of both. Create a `set` by applying `fn` to each element in `b`, then use list comprehension in combination with fn on a to only keep values not contained in the previously created `set`. diff --git a/snippets/factorial.md b/snippets/factorial.md index 2a303a11c..abbac44a2 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -1,5 +1,7 @@ -### factorial - +--- +title: factorial +tags: math +--- Calculates the factorial of a number. Use recursion. If `num` is less than or equal to `1`, return `1`. Otherwise, return the product of `num` and the factorial of `num - 1`. Throws an exception if `num` is a negative or a floating point number. diff --git a/snippets/fermat_test.md b/snippets/fermat_test.md index 676cf6435..112d1d9ed 100644 --- a/snippets/fermat_test.md +++ b/snippets/fermat_test.md @@ -1,5 +1,7 @@ -### fermat_test - +--- +title: fermat_test +tags: math +--- Checks if the number is prime or not. Returns True if passed number is prime, and False if not. The function uses Fermat's theorem. diff --git a/snippets/fibonacci.md b/snippets/fibonacci.md index c23000eb9..7b5b4e68a 100644 --- a/snippets/fibonacci.md +++ b/snippets/fibonacci.md @@ -1,5 +1,7 @@ -### fibonacci - +--- +title: fibonacci +tags: math +--- Generates an array, containing the Fibonacci sequence, up until the nth term. Starting with 0 and 1, adds the sum of the last two numbers of the list to the end of the list using ```list.append()``` until the length of the list reaches n. If the given nth value is 0 or less, the method will just return a list containing 0. diff --git a/snippets/fibonacci_until_num.md b/snippets/fibonacci_until_num.md index 12dc2fc04..5402662d4 100644 --- a/snippets/fibonacci_until_num.md +++ b/snippets/fibonacci_until_num.md @@ -1,5 +1,7 @@ -### fibonacci_until_num - +--- +title: fibonacci_until_num +tags: math +--- Returns the n-th term in a Fibonnaci sequence that starts with 1 A term in a Fibonnaci sequence is the sum of the two previous terms. diff --git a/snippets/gcd.md b/snippets/gcd.md index 2631cff6a..01ec425b1 100644 --- a/snippets/gcd.md +++ b/snippets/gcd.md @@ -1,5 +1,7 @@ -### gcd - +--- +title: gcd +tags: math +--- Calculates the greatest common divisor of a list of numbers. Uses the reduce function from the inbuilt module `functools`. Also uses the `math.gcd` function over a list. diff --git a/snippets/has_duplicates.md b/snippets/has_duplicates.md index 3a7535919..8a829fb37 100644 --- a/snippets/has_duplicates.md +++ b/snippets/has_duplicates.md @@ -1,5 +1,7 @@ -### has_duplicates - +--- +title: has_duplicates +tags: list +--- Checks a flat list for duplicate values. Returns True if duplicate values exist and False if values are all unique. This function compares the length of the list with length of the set() of the list. set() removes duplicate values from the list. diff --git a/snippets/insertion_sort.md b/snippets/insertion_sort.md index aa94cb006..0bd7af75a 100644 --- a/snippets/insertion_sort.md +++ b/snippets/insertion_sort.md @@ -1,5 +1,7 @@ -### insertion_sort - +--- +title: insertion_sort +tags: list +--- On a very basic level, an insertion sort algorithm contains the logic of shifting around and inserting elements in order to sort an unordered list of any size. The way that it goes about inserting elements, however, is what makes insertion sort so very interesting! ```python diff --git a/snippets/is_anagram.md b/snippets/is_anagram.md index 372ff3fbc..f6c14f914 100644 --- a/snippets/is_anagram.md +++ b/snippets/is_anagram.md @@ -1,5 +1,7 @@ -### is_anagram - +--- +title: is_anagram +tags: string +--- Determine if 2 strings are anagrams. Returns true if 2 strings are anagrams of each other, false otherwise. diff --git a/snippets/is_lower_case.md b/snippets/is_lower_case.md index 54164c1b3..da9341288 100644 --- a/snippets/is_lower_case.md +++ b/snippets/is_lower_case.md @@ -1,5 +1,7 @@ -### is_lower_case - +--- +title: is_lower_case +tags: string +--- Checks if a string is lower case. Convert the given string to lower case, using `str.lower()` method and compare it to the original. diff --git a/snippets/is_upper_case.md b/snippets/is_upper_case.md index 6169cd424..00554c297 100644 --- a/snippets/is_upper_case.md +++ b/snippets/is_upper_case.md @@ -1,5 +1,7 @@ -### is_upper_case - +--- +title: is_upper_case +tags: string +--- Checks if a string is upper case. Convert the given string to upper case, using `str.upper()` method and compare it to the original. diff --git a/snippets/keys_only.md b/snippets/keys_only.md index 7a566a1fd..8ca10d566 100644 --- a/snippets/keys_only.md +++ b/snippets/keys_only.md @@ -1,5 +1,7 @@ -### keys_only - +--- +title: keys_only +tags: object +--- Function which accepts a dictionary of key value pairs and returns a new flat list of only the keys. Uses the .keys() method of "dict" objects. dict.keys() returns a view object that displays a list of all the keys. Then, list(dict.keys()) returns a list that stores all the keys of a dict. diff --git a/snippets/lcm.md b/snippets/lcm.md index 17969c9b0..bdbf77938 100644 --- a/snippets/lcm.md +++ b/snippets/lcm.md @@ -1,5 +1,7 @@ -### lcm - +--- +title: lcm +tags: math +--- Returns the least common multiple of two or more numbers. Use the `greatest common divisor (GCD)` formula and the fact that `lcm(x,y) = x * y / gcd(x,y)` to determine the least common multiple. The GCD formula uses recursion. diff --git a/snippets/max_n.md b/snippets/max_n.md index b47ddbdcf..81e3e5afa 100644 --- a/snippets/max_n.md +++ b/snippets/max_n.md @@ -1,5 +1,7 @@ -### max_n - +--- +title: max_n +tags: math +--- Returns the `n` maximum elements from the provided list. If `n` is greater than or equal to the provided list's length, then return the original list(sorted in descending order). Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` module to create a shallow clone of the list and sort it in ascending order and then use `list.reverse()` reverse it to make it descending order. Use `[:n]` to get the specified number of elements. Omit the second argument, `n`, to get a one-element list diff --git a/snippets/min_n.md b/snippets/min_n.md index d6c942c64..6b3326a03 100644 --- a/snippets/min_n.md +++ b/snippets/min_n.md @@ -1,5 +1,7 @@ -### min_n - +--- +title: min_n +tags: math +--- Returns the `n` minimum elements from the provided list. If `n` is greater than or equal to the provided list's length, then return the original list(sorted in ascending order). Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` module to create a shallow clone of the list and sort it in ascending order. Use `[:n]` to get the specified number of elements. Omit the second argument, `n`, to get a one-element list diff --git a/snippets/palindrome.md b/snippets/palindrome.md index 4764aaf3a..593208c6c 100644 --- a/snippets/palindrome.md +++ b/snippets/palindrome.md @@ -1,5 +1,7 @@ -### palindrome - +--- +title: palindrome +tags: string +--- Returns `True` if the given string is a palindrome, `False` otherwise. Convert string `str.lower()` and use `re.sub` to remove non-alphanumeric characters from it. Then compare the new string to the reversed. diff --git a/snippets/shuffle.md b/snippets/shuffle.md index 3bcdec8b8..6b7fe1362 100644 --- a/snippets/shuffle.md +++ b/snippets/shuffle.md @@ -1,5 +1,7 @@ -### shuffle - +--- +title: shuffle +tags: list +--- :information_source: The same algorithm is already implemented via `random.shuffle`. Randomizes the order of the values of an list, returning a new list. diff --git a/snippets/spread.md b/snippets/spread.md index c37fae703..e261aa6a3 100644 --- a/snippets/spread.md +++ b/snippets/spread.md @@ -1,5 +1,7 @@ -### spread - +--- +title: spread +tags: list +--- Implements javascript's `[].concat(...arr)`. Flattens the list(non-deep) and returns an list. ```python diff --git a/snippets/unique_elements.md b/snippets/unique_elements.md index c064c51d4..8b9b80a42 100644 --- a/snippets/unique_elements.md +++ b/snippets/unique_elements.md @@ -1,5 +1,7 @@ -### unique_elements - +--- +title: unique_elements +tags: list +--- Returns the unique elements in a given list. The given `list` is first converted to a `set` using the `set()` function. By definition, a `set` cannot have duplicate elements. So, the duplicate elements are automatically removed. Before returning, we convert it back to a `list` diff --git a/snippets/values_only.md b/snippets/values_only.md index ddda0731d..8a4d7b94f 100644 --- a/snippets/values_only.md +++ b/snippets/values_only.md @@ -1,5 +1,7 @@ -### values_only - +--- +title: values_only +tags: object +--- Function which accepts a dictionary of key value pairs and returns a new flat list of only the values. Uses the .items() function with a for loop on the dictionary to track both the key and value of the iteration and returns a new list by appending the values to it. Best used on 1 level-deep key:value pair dictionaries and not nested data-structures. diff --git a/snippets/zip.md b/snippets/zip.md index bcb5567cd..516cb7c49 100644 --- a/snippets/zip.md +++ b/snippets/zip.md @@ -1,5 +1,7 @@ -### zip - +--- +title: zip +tags: list +--- :information_source: Already implemented via `itertools.zip_longest()` Creates a list of elements, grouped based on the position in the original lists. diff --git a/tag_database b/tag_database deleted file mode 100644 index e79fd0424..000000000 --- a/tag_database +++ /dev/null @@ -1,31 +0,0 @@ -average:math -chunk:list -compact:list -count_occurences:list -count_vowels:string -deep_flatten:list -difference:list -factorial:math -gcd:math -lcm:math -max_n:math -min_n:math -shuffle:list -spread:list -zip:list -byte_size:string -capitalize:string -capitalize_every_word:string -decapitalize:string -palindrome:string -is_upper_case:string -is_lower_case:string -count_by:list -difference_by:list -insertion_sort:list -bubble_sort:list -has_duplicates:list -keys_only:object -values_only:object -all_unique:object -fibonacci_until_num:math