diff --git a/snippet-template.md b/snippet-template.md index 92fb20788..b049ec653 100644 --- a/snippet-template.md +++ b/snippet-template.md @@ -5,7 +5,9 @@ tags: utility,intermediate Explain briefly what the snippet does. -Explain briefly how the snippet works. +- Explain briefly how the snippet works. +- Use bullet points for your snippet's explanation. +- Try to explain everything briefly but clearly. ```py def function_name(args): diff --git a/snippets/all_equal.md b/snippets/all_equal.md index 44233844d..45bdb8b62 100644 --- a/snippets/all_equal.md +++ b/snippets/all_equal.md @@ -5,7 +5,7 @@ tags: list,beginner Checks if all elements in a list are equal. -Use `[1:]` and `[:-1]` to compare all the values in the given list. +- Use `[1:]` and `[:-1]` to compare all the values in the given list. ```py def all_equal(lst): diff --git a/snippets/all_unique.md b/snippets/all_unique.md index 256771d36..687cf6806 100644 --- a/snippets/all_unique.md +++ b/snippets/all_unique.md @@ -5,7 +5,7 @@ tags: list,beginner Returns `True` if all the values in a list are unique, `False` otherwise. -Use `set()` on the given list to remove duplicates, use `len()` to compare its length with the length of the list. +- Use `set()` on the given list to remove duplicates, use `len()` to compare its length with the length of the list. ```py def all_unique(lst): diff --git a/snippets/arithmetic_progression.md b/snippets/arithmetic_progression.md index 788f11c62..143d25521 100644 --- a/snippets/arithmetic_progression.md +++ b/snippets/arithmetic_progression.md @@ -5,7 +5,7 @@ tags: math,beginner Returns a list of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit. -Use `range` and `list` with the appropriate start, step and end values. +- Use `range` and `list` with the appropriate start, step and end values. ```py def find_multiples(n, lim): diff --git a/snippets/average.md b/snippets/average.md index 0a663c3bc..f0da21b3b 100644 --- a/snippets/average.md +++ b/snippets/average.md @@ -5,7 +5,7 @@ tags: math,list,beginner Returns the average of two or more numbers. -Use `sum()` to sum all of the `args` provided, divide by `len(args)`. +- Use `sum()` to sum all of the `args` provided, divide by `len(args)`. ```py def average(*args): diff --git a/snippets/average_by.md b/snippets/average_by.md index f88fd9667..8acf1cd1b 100644 --- a/snippets/average_by.md +++ b/snippets/average_by.md @@ -5,8 +5,8 @@ tags: math,list,function,intermediate Returns the average of a list, after mapping each element to a value using the provided function. -Use `map()` to map each element to the value returned by `fn`. -Use `sum()` to sum all of the mapped values, divide by `len(lst)`. +- Use `map()` to map each element to the value returned by `fn`. +- Use `sum()` to sum all of the mapped values, divide by `len(lst)`. ```py def average_by(lst, fn=lambda x: x): diff --git a/snippets/bifurcate.md b/snippets/bifurcate.md index d430470dc..1fc42c7b3 100644 --- a/snippets/bifurcate.md +++ b/snippets/bifurcate.md @@ -6,7 +6,7 @@ tags: list,intermediate Splits values into two groups. If an element in `filter` is `True`, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group. -Use list comprehension and `enumerate()` to add elements to groups, based on `filter`. +- Use list comprehension and `enumerate()` to add elements to groups, based on `filter`. ```py def bifurcate(lst, filter): diff --git a/snippets/bifurcate_by.md b/snippets/bifurcate_by.md index fd141bb81..f0facf23a 100644 --- a/snippets/bifurcate_by.md +++ b/snippets/bifurcate_by.md @@ -6,7 +6,7 @@ tags: list,function,intermediate Splits values into two groups according to a function, which specifies which group an element in the input list belongs to. If the function returns `True`, the element belongs to the first group; otherwise, it belongs to the second group. -Use list comprehension to add elements to groups, based on `fn`. +- Use list comprehension to add elements to groups, based on `fn`. ```py def bifurcate_by(lst, fn): diff --git a/snippets/byte_size.md b/snippets/byte_size.md index eb2b06363..c5427ee2c 100644 --- a/snippets/byte_size.md +++ b/snippets/byte_size.md @@ -5,7 +5,7 @@ tags: string, beginner Returns the length of a string in bytes. -Use `s.encode('utf-8')` to encode the given string and return its length. +- Use `s.encode('utf-8')` to encode the given string and return its length. ```py def byte_size(s): diff --git a/snippets/camel.md b/snippets/camel.md index 4e140054d..54d5a7d9b 100644 --- a/snippets/camel.md +++ b/snippets/camel.md @@ -5,9 +5,9 @@ tags: string,regexp,intermediate Converts a string to camelcase. -Use `re.sub()` to replace any `-` or `_` with a space, using the regexp `r"(_|-)+"`. -Use `title()` to capitalize the first letter of each word convert the rest to lowercase. -Finally, use `replace()` to remove spaces between words. +- Use `re.sub()` to replace any `-` or `_` with a space, using the regexp `r"(_|-)+"`. +- Use `title()` to capitalize the first letter of each word convert the rest to lowercase. +- Finally, use `replace()` to remove spaces between words. ```py from re import sub diff --git a/snippets/capitalize.md b/snippets/capitalize.md index 207797efb..ca1e7a61f 100644 --- a/snippets/capitalize.md +++ b/snippets/capitalize.md @@ -5,8 +5,8 @@ tags: string,intermediate Capitalizes the first letter of a string. -Capitalize the first letter of the string and then add 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. +- Capitalize the first letter of the string and then add 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. ```py def capitalize(s, lower_rest=False): diff --git a/snippets/capitalize_every_word.md b/snippets/capitalize_every_word.md index c26d4ecef..16c159b0d 100644 --- a/snippets/capitalize_every_word.md +++ b/snippets/capitalize_every_word.md @@ -5,7 +5,7 @@ tags: string,beginner Capitalizes the first letter of every word in a string. -Use `s.title()` to capitalize first letter of every word in the string. +- Use `s.title()` to capitalize first letter of every word in the string. ```py def capitalize_every_word(s): diff --git a/snippets/cast_list.md b/snippets/cast_list.md index f1295f137..e77f10845 100644 --- a/snippets/cast_list.md +++ b/snippets/cast_list.md @@ -5,7 +5,7 @@ tags: list,beginner Casts the provided value as a list if it's not one. -Use `isinstance()` to check if the given value is enumerable and return it by using `list()` or encapsulated in a list accordingly. +- Use `isinstance()` to check if the given value is enumerable and return it by using `list()` or encapsulated in a list accordingly. ```py def cast_list(val): diff --git a/snippets/celsius_to_fahrenheit.md b/snippets/celsius_to_fahrenheit.md index 1ea9ff4e3..9b86fe4eb 100644 --- a/snippets/celsius_to_fahrenheit.md +++ b/snippets/celsius_to_fahrenheit.md @@ -5,7 +5,7 @@ tags: math,beginner Converts Celsius to Fahrenheit. -Use the formula `fahrenheit = (celsius * 1.8) + 32` to convert from Celsius to Fahrenheit. +- Use the formula `fahrenheit = (celsius * 1.8) + 32` to convert from Celsius to Fahrenheit. ```py def celsius_to_fahrenheit(celsius): diff --git a/snippets/check_prop.md b/snippets/check_prop.md index 4a1d519dc..b96313f69 100644 --- a/snippets/check_prop.md +++ b/snippets/check_prop.md @@ -5,7 +5,7 @@ tags: function,intermediate Given a predicate function, `fn`, and a `prop` string, this curried function will then take an object to inspect by calling the property and passing it to the predicate. -Return a `lambda` function that takes an object and applies the predicate function, `fn` to the specified property. +- Return a `lambda` function that takes an object and applies the predicate function, `fn` to the specified property. ```py def check_prop(fn, prop): diff --git a/snippets/chunk.md b/snippets/chunk.md index 8b127c1ed..b7b49614c 100644 --- a/snippets/chunk.md +++ b/snippets/chunk.md @@ -5,9 +5,9 @@ tags: list,intermediate Chunks a list into smaller lists of a specified size. -Use `list()` and `range()` to create a list of the desired `size`. -Use `map()` on the list and fill it with splices of the given list. -Finally, return the created list. +- Use `list()` and `range()` to create a list of the desired `size`. +- Use `map()` on the list and fill it with splices of the given list. +- Finally, return the created list. ```py from math import ceil diff --git a/snippets/clamp_number.md b/snippets/clamp_number.md index 44cf448a5..0ab98515e 100644 --- a/snippets/clamp_number.md +++ b/snippets/clamp_number.md @@ -5,8 +5,8 @@ tags: math,beginner Clamps `num` within the inclusive range specified by the boundary values `a` and `b`. -If `num` falls within the range, return `num`. -Otherwise, return the nearest number in the range. +- If `num` falls within the range, return `num`. +- Otherwise, return the nearest number in the range. ```py def clamp_number(num,a,b): diff --git a/snippets/collect_dictionary.md b/snippets/collect_dictionary.md index 52ed1a9db..d02bfefc4 100644 --- a/snippets/collect_dictionary.md +++ b/snippets/collect_dictionary.md @@ -5,7 +5,7 @@ tags: dictionary,intermediate Inverts a dictionary with non-unique hashable values. -Use `dictionary.items()` in combination with a loop to map the values of the dictionary to keys using `dictionary.setdefault()`, `list()` and `append()` to create a list for each one. +- Use `dictionary.items()` in combination with a loop to map the values of the dictionary to keys using `dictionary.setdefault()`, `list()` and `append()` to create a list for each one. ```py def collect_dictionary(obj): diff --git a/snippets/compact.md b/snippets/compact.md index e09d3f022..05e28fb6d 100644 --- a/snippets/compact.md +++ b/snippets/compact.md @@ -5,7 +5,7 @@ tags: list,beginner Removes falsey values from a list. -Use `filter()` to filter out falsey values (`False`, `None`, `0`, and `""`). +- Use `filter()` to filter out falsey values (`False`, `None`, `0`, and `""`). ```py def compact(lst): diff --git a/snippets/compose.md b/snippets/compose.md index fff94ea65..4cb6bbf3c 100644 --- a/snippets/compose.md +++ b/snippets/compose.md @@ -5,8 +5,8 @@ tags: function,intermediate Performs right-to-left function composition. -Use `functools.reduce()` to perform right-to-left function composition. -The last (rightmost) function can accept one or more arguments; the remaining functions must be unary. +- Use `functools.reduce()` to perform right-to-left function composition. +- The last (rightmost) function can accept one or more arguments; the remaining functions must be unary. ```py from functools import reduce diff --git a/snippets/compose_right.md b/snippets/compose_right.md index 4ee634b94..e300e9278 100644 --- a/snippets/compose_right.md +++ b/snippets/compose_right.md @@ -5,8 +5,8 @@ tags: function,intermediate Performs left-to-right function composition. -Use `functools.reduce()` to perform left-to-right function composition. -The first (leftmost) function can accept one or more arguments; the remaining functions must be unary. +- Use `functools.reduce()` to perform left-to-right function composition. +- The first (leftmost) function can accept one or more arguments; the remaining functions must be unary. ```py from functools import reduce diff --git a/snippets/count_by.md b/snippets/count_by.md index 9d50bf8a7..4fa78534c 100644 --- a/snippets/count_by.md +++ b/snippets/count_by.md @@ -5,8 +5,8 @@ tags: list,intermediate Groups the elements of a list based on the given function and returns the count of elements in each group. -Use `map()` to map the values of the given list using the given function. -Iterate over the map and increase the element count each time it occurs. +- Use `map()` to map the values of the given list using the given function. +- Iterate over the map and increase the element count each time it occurs. ```py def count_by(arr, fn=lambda x: x): diff --git a/snippets/count_occurences.md b/snippets/count_occurences.md index 7c5c4dd6c..f75b24376 100644 --- a/snippets/count_occurences.md +++ b/snippets/count_occurences.md @@ -5,7 +5,7 @@ tags: list,beginner Counts the occurrences of a value in a list. -Increment a counter for every item in the list that has the given value and is of the same type. +- Increment a counter for every item in the list that has the given value and is of the same type. ```py def count_occurrences(lst, val): diff --git a/snippets/curry.md b/snippets/curry.md index 4f9b5e7c0..d5ca6573b 100644 --- a/snippets/curry.md +++ b/snippets/curry.md @@ -5,7 +5,7 @@ tags: function,intermediate Curries a function. -Use `functools.partial()` to return a new partial object which behaves like `fn` with the given arguments, `args`, partially applied. +- Use `functools.partial()` to return a new partial object which behaves like `fn` with the given arguments, `args`, partially applied. ```py from functools import partial diff --git a/snippets/decapitalize.md b/snippets/decapitalize.md index cd9c94b84..21d02f013 100644 --- a/snippets/decapitalize.md +++ b/snippets/decapitalize.md @@ -5,8 +5,8 @@ tags: string,intermediate Decapitalizes the first letter of a string. -Decapitalize the first letter of the string and then add 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. +- Decapitalize the first letter of the string and then add 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. ```py def decapitalize(s, upper_rest=False): diff --git a/snippets/deep_flatten.md b/snippets/deep_flatten.md index c92278691..8d489ae02 100644 --- a/snippets/deep_flatten.md +++ b/snippets/deep_flatten.md @@ -5,9 +5,9 @@ tags: list,recursion,intermediate Deep flattens a list. -Use recursion. -Use `isinstance()` with `collections.abc.Iterable` to check if an element is iterable. -If it is, apply `deep_flatten()` recursively, otherwise return `[lst]`. +- Use recursion. +- Use `isinstance()` with `collections.abc.Iterable` to check if an element is iterable. +- If it is, apply `deep_flatten()` recursively, otherwise return `[lst]`. ```py from collections.abc import Iterable diff --git a/snippets/degrees_to_rads.md b/snippets/degrees_to_rads.md index 5ee50cce3..816988baf 100644 --- a/snippets/degrees_to_rads.md +++ b/snippets/degrees_to_rads.md @@ -5,7 +5,7 @@ tags: math,beginner Converts an angle from degrees to radians. -Use `math.pi` and the degrees to radians formula to convert the angle from degrees to radians. +- Use `math.pi` and the degrees to radians formula to convert the angle from degrees to radians. ```py from math import pi diff --git a/snippets/delay.md b/snippets/delay.md index 499b32485..7494c528f 100644 --- a/snippets/delay.md +++ b/snippets/delay.md @@ -5,7 +5,7 @@ tags: function,intermediate Invokes the provided function after `ms` milliseconds. -Use `time.sleep()` to delay the execution of `fn` by `ms / 1000` seconds. +- Use `time.sleep()` to delay the execution of `fn` by `ms / 1000` seconds. ```py from time import sleep diff --git a/snippets/difference.md b/snippets/difference.md index 2391a9837..9db4c4982 100644 --- a/snippets/difference.md +++ b/snippets/difference.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the difference between two iterables. -Create a `set` from `b`, then use list comprehension on `a` to only keep values not contained in the previously created set, `_b`. +- Create a `set` from `b`, then use list comprehension on `a` to only keep values not contained in the previously created set, `_b`. ```py def difference(a, b): diff --git a/snippets/difference_by.md b/snippets/difference_by.md index 3baa2308f..c70d1e67f 100644 --- a/snippets/difference_by.md +++ b/snippets/difference_by.md @@ -5,7 +5,7 @@ tags: list,function,intermediate Returns the difference between two lists, 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, `_b`. +- 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, `_b`. ```py def difference_by(a, b, fn): diff --git a/snippets/digitize.md b/snippets/digitize.md index 74eb0c0d2..fed9b46bf 100644 --- a/snippets/digitize.md +++ b/snippets/digitize.md @@ -5,7 +5,7 @@ tags: math,list,beginner Converts a number to a list of digits. -Use `map()` combined with `int` on the string representation of `n` and return a list from the result. +- Use `map()` combined with `int` on the string representation of `n` and return a list from the result. ```py def digitize(n): diff --git a/snippets/drop.md b/snippets/drop.md index c00bcbe24..523570b15 100644 --- a/snippets/drop.md +++ b/snippets/drop.md @@ -5,7 +5,7 @@ tags: list,beginner Returns a list with `n` elements removed from the left. -Use slice notation to remove the specified number of elements from the left. +- Use slice notation to remove the specified number of elements from the left. ```py def drop(a, n = 1): diff --git a/snippets/drop_right.md b/snippets/drop_right.md index 21eaa672c..357e741d9 100644 --- a/snippets/drop_right.md +++ b/snippets/drop_right.md @@ -5,7 +5,7 @@ tags: list,beginner Returns a list with `n` elements removed from the right. -Use slice notation to remove the specified number of elements from the right. +- Use slice notation to remove the specified number of elements from the right. ```py def drop_right(a, n = 1): diff --git a/snippets/every.md b/snippets/every.md index dde0f1a03..f848f5eee 100644 --- a/snippets/every.md +++ b/snippets/every.md @@ -5,7 +5,7 @@ tags: list,function,intermediate Returns `True` if the provided function returns `True` for every element in the list, `False` otherwise. -Use `all()` in combination with `map` and `fn` to check if `fn` returns `True` for all elements in the list. +- Use `all()` in combination with `map` and `fn` to check if `fn` returns `True` for all elements in the list. ```py def every(lst, fn=lambda x: x): diff --git a/snippets/every_nth.md b/snippets/every_nth.md index f747b8e83..5fb99bbe2 100644 --- a/snippets/every_nth.md +++ b/snippets/every_nth.md @@ -5,7 +5,7 @@ tags: list,beginner Returns every nth element in a list. -Use `[nth-1::nth]` to create a new list that contains every nth element of the given list. +- Use `[nth-1::nth]` to create a new list that contains every nth element of the given list. ```py def every_nth(lst, nth): diff --git a/snippets/factorial.md b/snippets/factorial.md index e69783877..c5bcbb2e0 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -5,10 +5,10 @@ tags: math,recursion,beginner 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. +- 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. ```py def factorial(num): diff --git a/snippets/fahrenheit_to_celsius.md b/snippets/fahrenheit_to_celsius.md index 976f9b3db..e1efbaae7 100644 --- a/snippets/fahrenheit_to_celsius.md +++ b/snippets/fahrenheit_to_celsius.md @@ -5,7 +5,7 @@ tags: math,beginner Converts Fahrenheit to Celsius. -Use the formula `celsius = (fahrenheit - 32) / 1.8` to convert from Fahrenheit to Celsius. +- Use the formula `celsius = (fahrenheit - 32) / 1.8` to convert from Fahrenheit to Celsius. ```py def fahrenheit_to_celsius(fahrenheit): diff --git a/snippets/fibonacci.md b/snippets/fibonacci.md index 6d27dfbb8..5e0cc3bcc 100644 --- a/snippets/fibonacci.md +++ b/snippets/fibonacci.md @@ -5,8 +5,8 @@ tags: math,list,intermediate Generates a list, containing the Fibonacci sequence, up until the nth term. -Starting with `0` and `1`, use `list.append()` to add the sum of the last two numbers of the list to the end of the list, until the length of the list reaches `n`. -If `n` is less or equal to `0`, return a list containing `0`. +- Starting with `0` and `1`, use `list.append()` to add the sum of the last two numbers of the list to the end of the list, until the length of the list reaches `n`. +- If `n` is less or equal to `0`, return a list containing `0`. ```py def fibonacci(n): diff --git a/snippets/filter_non_unique.md b/snippets/filter_non_unique.md index a22540af3..ec6f68763 100644 --- a/snippets/filter_non_unique.md +++ b/snippets/filter_non_unique.md @@ -5,8 +5,8 @@ tags: list,beginner Filters out the non-unique values in a list. -Use a `collections.Counter` to get the count of each value in the list. -Use list comprehension to create a list containing only the unique values. +- Use a `collections.Counter` to get the count of each value in the list. +- Use list comprehension to create a list containing only the unique values. ```py from collections import Counter diff --git a/snippets/filter_unique.md b/snippets/filter_unique.md index 2f3a73031..ccc72e5da 100644 --- a/snippets/filter_unique.md +++ b/snippets/filter_unique.md @@ -5,8 +5,8 @@ tags: list,beginner Filters out the unique values in a list. -Use a `collections.Counter` to get the count of each value in the list. -Use list comprehension to create a list containing only the non-unique values. +- Use a `collections.Counter` to get the count of each value in the list. +- Use list comprehension to create a list containing only the non-unique values. ```py from collections import Counter diff --git a/snippets/find.md b/snippets/find.md index 186304622..712797881 100644 --- a/snippets/find.md +++ b/snippets/find.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the value of the first element in the provided list that satisfies the provided testing function. -Use list comprehension and `next()` to return the first element in `lst` for which `fn` returns `True`. +- Use list comprehension and `next()` to return the first element in `lst` for which `fn` returns `True`. ```py def find(lst, fn): diff --git a/snippets/find_index.md b/snippets/find_index.md index 48ce55556..8849178ad 100644 --- a/snippets/find_index.md +++ b/snippets/find_index.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the index of the first element in the provided list that satisfies the provided testing function. -Use list comprehension, `enumerate()` and `next()` to return the index of the first element in `lst` for which `fn` returns `True`. +- Use list comprehension, `enumerate()` and `next()` to return the index of the first element in `lst` for which `fn` returns `True`. ```py def find_index(lst, fn): diff --git a/snippets/find_key.md b/snippets/find_key.md index 455666e34..ad21dd819 100644 --- a/snippets/find_key.md +++ b/snippets/find_key.md @@ -5,7 +5,7 @@ tags: dictionary,intermediate Returns the first key in the provided dictionary that has the given value. -Use `dictionary.items()` and `next()` to return the first key that has a value equal to `val`. +- Use `dictionary.items()` and `next()` to return the first key that has a value equal to `val`. ```py def find_key(dict, val): diff --git a/snippets/find_keys.md b/snippets/find_keys.md index 757c08d6a..689230ef2 100644 --- a/snippets/find_keys.md +++ b/snippets/find_keys.md @@ -5,7 +5,7 @@ tags: dictionary,intermediate Returns all keys in the provided dictionary that have the given value. -Use `dictionary.items()`, a generator and `list()` to return all keys that have a value equal to `val`. +- Use `dictionary.items()`, a generator and `list()` to return all keys that have a value equal to `val`. ```py def find_keys(dict, val): diff --git a/snippets/find_last.md b/snippets/find_last.md index ece374144..5aa78aaec 100644 --- a/snippets/find_last.md +++ b/snippets/find_last.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the value of the last element in the provided list that satisfies the provided testing function. -Use list comprehension and `next()` to return the last element in `lst` for which `fn` returns `True`. +- Use list comprehension and `next()` to return the last element in `lst` for which `fn` returns `True`. ```py def find_last(lst, fn): diff --git a/snippets/find_last_index.md b/snippets/find_last_index.md index 2eb60755f..ef3616cb8 100644 --- a/snippets/find_last_index.md +++ b/snippets/find_last_index.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the index of the last element in the provided list that satisfies the provided testing function. -Use list comprehension, `enumerate()` and `next()` to return the index of the last element in `lst` for which `fn` returns `True`. +- Use list comprehension, `enumerate()` and `next()` to return the index of the last element in `lst` for which `fn` returns `True`. ```py def find_last_index(lst, fn): diff --git a/snippets/find_parity_outliers.md b/snippets/find_parity_outliers.md index 10b03e7ea..487abb626 100644 --- a/snippets/find_parity_outliers.md +++ b/snippets/find_parity_outliers.md @@ -5,8 +5,8 @@ tags: list,math,intermediate Given a list, returns the items that are parity outliers. -Use `collections.Counter` with a list comprehension to count even and odd values in the list, use `collections.Counter.most_common()` to get the most common parity. -Use a list comprehension to find all elements that do not match the most common parity. +- Use `collections.Counter` with a list comprehension to count even and odd values in the list, use `collections.Counter.most_common()` to get the most common parity. +- Use a list comprehension to find all elements that do not match the most common parity. ```py from collections import Counter diff --git a/snippets/flatten.md b/snippets/flatten.md index f2306241b..89331dc0c 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -5,7 +5,7 @@ tags: list,intermediate Flattens a list of lists once. -Use nested list comprehension to extract each value from sub-lists in order. +- Use nested list comprehension to extract each value from sub-lists in order. ```py def flatten(lst): diff --git a/snippets/for_each.md b/snippets/for_each.md index d4b36999d..16bb81070 100644 --- a/snippets/for_each.md +++ b/snippets/for_each.md @@ -5,7 +5,7 @@ tags: list,beginner Executes the provided function once for each list element. -Use a `for` loop to execute `fn` for each element in `itr`. +- Use a `for` loop to execute `fn` for each element in `itr`. ```py def for_each(itr, fn): diff --git a/snippets/for_each_right.md b/snippets/for_each_right.md index 64bb2e075..819172931 100644 --- a/snippets/for_each_right.md +++ b/snippets/for_each_right.md @@ -5,7 +5,7 @@ tags: list,beginner Executes the provided function once for each list element, starting from the list's last element. -Use a `for` loop in combination with slice notation to execute `fn` for each element in `itr`, starting from the last one. +- Use a `for` loop in combination with slice notation to execute `fn` for each element in `itr`, starting from the last one. ```py def for_each_right(itr, fn): diff --git a/snippets/frequencies.md b/snippets/frequencies.md index f260e7353..9e16a8ea8 100644 --- a/snippets/frequencies.md +++ b/snippets/frequencies.md @@ -5,7 +5,7 @@ tags: list,intermediate Returns a dictionary with the unique values of a list as keys and their frequencies as the values. -Use a `for` loop to populate a dictionary, `f`, with the unique values in `lst` as keys, adding to existing keys every time the same value is encountered. +- Use a `for` loop to populate a dictionary, `f`, with the unique values in `lst` as keys, adding to existing keys every time the same value is encountered. ```py from functools import reduce diff --git a/snippets/gcd.md b/snippets/gcd.md index e3b6adb44..57a637044 100644 --- a/snippets/gcd.md +++ b/snippets/gcd.md @@ -5,7 +5,7 @@ tags: math,beginner Calculates the greatest common divisor of a list of numbers. -Use `functools.reduce()` and `math.gcd()` over the given list. +- Use `functools.reduce()` and `math.gcd()` over the given list. ```py from functools import reduce diff --git a/snippets/group_by.md b/snippets/group_by.md index 0a20e22cf..a6ca81b4a 100644 --- a/snippets/group_by.md +++ b/snippets/group_by.md @@ -5,8 +5,8 @@ tags: list,dictionary,intermediate Groups the elements of a list based on the given function. -Use `map()` and `fn` to map the values of the list to the keys of a dictionary. -Use list comprehension to map each element to the appropriate `key`. +- Use `map()` and `fn` to map the values of the list to the keys of a dictionary. +- Use list comprehension to map each element to the appropriate `key`. ```py def group_by(lst, fn): diff --git a/snippets/has_duplicates.md b/snippets/has_duplicates.md index f9e092219..be8a1e8e6 100644 --- a/snippets/has_duplicates.md +++ b/snippets/has_duplicates.md @@ -5,7 +5,7 @@ tags: list,beginner Returns `True` if there are duplicate values in a flat list, `False` otherwise. -Use `set()` on the given list to remove duplicates, compare its length with the length of the list. +- Use `set()` on the given list to remove duplicates, compare its length with the length of the list. ```py def has_duplicates(lst): diff --git a/snippets/have_same_contents.md b/snippets/have_same_contents.md index 15f8baa57..a188a8e31 100644 --- a/snippets/have_same_contents.md +++ b/snippets/have_same_contents.md @@ -5,9 +5,9 @@ tags: list,intermediate Returns `True` if two lists contain the same elements regardless of order, `False` otherwise. -Use `set()` on the combination of both lists to find the unique values. -Iterate over them with a `for` loop comparing the `count()` of each unique value in each list. -Return `False` if the counts do not match for any element, `True` otherwise. +- Use `set()` on the combination of both lists to find the unique values. +- Iterate over them with a `for` loop comparing the `count()` of each unique value in each list. +- Return `False` if the counts do not match for any element, `True` otherwise. ```py def have_same_contents(a, b): diff --git a/snippets/head.md b/snippets/head.md index 536a3a473..4102080ca 100644 --- a/snippets/head.md +++ b/snippets/head.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the head of a list. -Use `lst[0]` to return the first element of the passed list. +- Use `lst[0]` to return the first element of the passed list. ```py def head(lst): diff --git a/snippets/hex_to_rgb.md b/snippets/hex_to_rgb.md index 3acf01ecf..1771d7085 100644 --- a/snippets/hex_to_rgb.md +++ b/snippets/hex_to_rgb.md @@ -5,8 +5,8 @@ tags: string,math,intermediate Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components. -Use a list comprehension in combination with `int()` and list slice notation to get the RGB components from the hexadecimal string. -Use `tuple()` to convert the resulting list to a tuple. +- Use a list comprehension in combination with `int()` and list slice notation to get the RGB components from the hexadecimal string. +- Use `tuple()` to convert the resulting list to a tuple. ```py def hex_to_rgb(hex): diff --git a/snippets/in_range.md b/snippets/in_range.md index 9a03d120e..97583523a 100644 --- a/snippets/in_range.md +++ b/snippets/in_range.md @@ -5,8 +5,8 @@ tags: math,beginner Checks if the given number falls within the given range. -Use arithmetic comparison to check if the given number is in the specified range. -If the second parameter, `end`, is not specified, the range is considered to be from `0` to `start`. +- Use arithmetic comparison to check if the given number is in the specified range. +- If the second parameter, `end`, is not specified, the range is considered to be from `0` to `start`. ```py def in_range(n, start, end = 0): diff --git a/snippets/includes_all.md b/snippets/includes_all.md index 1ce222623..80a6e14fe 100644 --- a/snippets/includes_all.md +++ b/snippets/includes_all.md @@ -5,7 +5,7 @@ tags: list,intermediate Returns `True` if all the elements in `values` are included in `lst`, `False` otherwise. -Check if every value in `values` is contained in `lst` using a `for` loop, returning `False` if any one value is not found, `True` otherwise. +- Check if every value in `values` is contained in `lst` using a `for` loop, returning `False` if any one value is not found, `True` otherwise. ```py def includes_all(lst, values): diff --git a/snippets/includes_any.md b/snippets/includes_any.md index 459953b11..5f14d66e1 100644 --- a/snippets/includes_any.md +++ b/snippets/includes_any.md @@ -5,7 +5,7 @@ tags: list,intermediate Returns `True` if any element in `values` is included in `lst`, `False` otherwise. -Check if any value in `values` is contained in `lst` using a `for` loop, returning `True` if any one value is found, `False` otherwise. +- Check if any value in `values` is contained in `lst` using a `for` loop, returning `True` if any one value is found, `False` otherwise. ```py def includes_any(lst, values): diff --git a/snippets/initial.md b/snippets/initial.md index ac40fecc0..cb53c5df8 100644 --- a/snippets/initial.md +++ b/snippets/initial.md @@ -5,7 +5,7 @@ tags: list,beginner Returns all the elements of a list except the last one. -Use `lst[0:-1]` to return all but the last element of the list. +- Use `lst[0:-1]` to return all but the last element of the list. ```py def initial(lst): diff --git a/snippets/initialize_2d_list.md b/snippets/initialize_2d_list.md index 08cb119ca..c7941c72f 100644 --- a/snippets/initialize_2d_list.md +++ b/snippets/initialize_2d_list.md @@ -5,8 +5,8 @@ tags: list,intermediate Initializes a 2D list of given width and height and value. -Use list comprehension and `range()` to generate `h` rows where each is a list with length `h`, initialized with `val`. -If `val` is not provided, default to `None`. +- Use list comprehension and `range()` to generate `h` rows where each is a list with length `h`, initialized with `val`. +- If `val` is not provided, default to `None`. ```py def initialize_2d_list(w,h, val = None): diff --git a/snippets/initialize_list_with_range.md b/snippets/initialize_list_with_range.md index c258a4329..41959f78f 100644 --- a/snippets/initialize_list_with_range.md +++ b/snippets/initialize_list_with_range.md @@ -5,9 +5,9 @@ tags: list,beginner Initializes a list containing the numbers in the specified range where `start` and `end` are inclusive with their common difference `step`. -Use `list` and `range()` to generate a list of the appropriate length, filled with the desired values in the given range. -Omit `start` to use the default value of `0`. -Omit `step` to use the default value of `1`. +- Use `list` and `range()` to generate a list of the appropriate length, filled with the desired values in the given range. +- Omit `start` to use the default value of `0`. +- Omit `step` to use the default value of `1`. ```py def initialize_list_with_range(end, start=0, step=1): diff --git a/snippets/initialize_list_with_values.md b/snippets/initialize_list_with_values.md index 918d77fa4..07314a6c7 100644 --- a/snippets/initialize_list_with_values.md +++ b/snippets/initialize_list_with_values.md @@ -5,8 +5,8 @@ tags: list,beginner Initializes and fills a list with the specified value. -Use list comprehension and `range()` to generate a list of length equal to `n`, filled with the desired values. -Omit `val` to use the default value of `0`. +- Use list comprehension and `range()` to generate a list of length equal to `n`, filled with the desired values. +- Omit `val` to use the default value of `0`. ```py def initialize_list_with_values(n, val = 0): diff --git a/snippets/intersection.md b/snippets/intersection.md index 13fc84977..5ca26a174 100644 --- a/snippets/intersection.md +++ b/snippets/intersection.md @@ -5,7 +5,7 @@ tags: list,beginner Returns a list of elements that exist in both lists. -Create a `set` from `a` and `b`, then use the built-in set operator `&` to only keep values contained in both sets, then transform the `set` back into a `list`. +- Create a `set` from `a` and `b`, then use the built-in set operator `&` to only keep values contained in both sets, then transform the `set` back into a `list`. ```py def intersection(a, b): diff --git a/snippets/intersection_by.md b/snippets/intersection_by.md index 2601c36ec..2a8ef7ad0 100644 --- a/snippets/intersection_by.md +++ b/snippets/intersection_by.md @@ -5,7 +5,7 @@ tags: list,function,intermediate Returns a list of elements that exist in both lists, 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 contained in both lists. +- 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 contained in both lists. ```py def intersection_by(a, b, fn): diff --git a/snippets/invert_dictionary.md b/snippets/invert_dictionary.md index b30ef9572..ac7f34f5d 100644 --- a/snippets/invert_dictionary.md +++ b/snippets/invert_dictionary.md @@ -5,7 +5,7 @@ tags: dictionary,intermediate Inverts a dictionary with unique hashable values. -Use `dictionary.items()` in combination with a list comprehension to create a new dictionary with the values and keys inverted. +- Use `dictionary.items()` in combination with a list comprehension to create a new dictionary with the values and keys inverted. ```py def invert_dictionary(obj): diff --git a/snippets/is_anagram.md b/snippets/is_anagram.md index 2f7e31705..55543f353 100644 --- a/snippets/is_anagram.md +++ b/snippets/is_anagram.md @@ -5,8 +5,8 @@ tags: string,intermediate Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters). -Use `isalnum()` to filter out non-alphanumeric characters, `lower()` to transform each character to lowercase. -Use `collections.Counter` to count the resulting characters for each string and compare the results. +- Use `isalnum()` to filter out non-alphanumeric characters, `lower()` to transform each character to lowercase. +- Use `collections.Counter` to count the resulting characters for each string and compare the results. ```py from collections import Counter diff --git a/snippets/is_contained_in.md b/snippets/is_contained_in.md index 1491bcb65..1ec234cb7 100644 --- a/snippets/is_contained_in.md +++ b/snippets/is_contained_in.md @@ -5,9 +5,7 @@ tags: list,intermediate Returns `True` if the elements of the first list are contained in the second one regardless of order, `False` otherwise. - -Use `count()` to check if any value in `a` has more occurences than it has in `b`, returning `False` if any such value is found, `True` otherwise. - +- Use `count()` to check if any value in `a` has more occurences than it has in `b`, returning `False` if any such value is found, `True` otherwise. ```py def is_contained_in(a, b): diff --git a/snippets/is_divisible.md b/snippets/is_divisible.md index 0f7f5d555..7494f9486 100644 --- a/snippets/is_divisible.md +++ b/snippets/is_divisible.md @@ -5,7 +5,7 @@ tags: math,beginner Checks if the first numeric argument is divisible by the second one. -Use the modulo operator (`%`) to check if the remainder is equal to `0`. +- Use the modulo operator (`%`) to check if the remainder is equal to `0`. ```py def is_divisible(dividend, divisor): diff --git a/snippets/is_even.md b/snippets/is_even.md index 5f15db6a5..e5951808e 100644 --- a/snippets/is_even.md +++ b/snippets/is_even.md @@ -5,8 +5,8 @@ tags: math,beginner Returns `True` if the given number is even, `False` otherwise. -Checks whether a number is odd or even using the modulo (`%`) operator. -Returns `True` if the number is even, `False` if the number is odd. +- Checks whether a number is odd or even using the modulo (`%`) operator. +- Returns `True` if the number is even, `False` if the number is odd. ```py def is_even(num): diff --git a/snippets/is_odd.md b/snippets/is_odd.md index 89a564d9f..ea199b423 100644 --- a/snippets/is_odd.md +++ b/snippets/is_odd.md @@ -5,8 +5,8 @@ tags: math,beginner Returns `True` if the given number is odd, `False` otherwise. -Checks whether a number is even or odd using the modulo (`%`) operator. -Returns `True` if the number is odd, `False` if the number is even. +- Checks whether a number is even or odd using the modulo (`%`) operator. +- Returns `True` if the number is odd, `False` if the number is even. ```py def is_odd(num): diff --git a/snippets/kebab.md b/snippets/kebab.md index c4aa6386a..e9c7dcead 100644 --- a/snippets/kebab.md +++ b/snippets/kebab.md @@ -5,7 +5,7 @@ tags: string,regexp,intermediate Converts a string to kebab case. -Break the string into words and combine them adding `-` as a separator, using a regexp. +- Break the string into words and combine them adding `-` as a separator, using a regexp. ```py from re import sub diff --git a/snippets/keys_only.md b/snippets/keys_only.md index e43e13cb9..a959f8872 100644 --- a/snippets/keys_only.md +++ b/snippets/keys_only.md @@ -5,8 +5,8 @@ tags: dictionary,list,beginner Returns a flat list of all the keys in a flat dictionary. -Use `dict.keys()` to return the keys in the given dictionary. -Return a `list()` of the previous result. +- Use `dict.keys()` to return the keys in the given dictionary. +- Return a `list()` of the previous result. ```py def keys_only(flat_dict): diff --git a/snippets/last.md b/snippets/last.md index 84c216843..8d6289598 100644 --- a/snippets/last.md +++ b/snippets/last.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the last element in a list. -use `lst[-1]` to return the last element of the passed list. +- use `lst[-1]` to return the last element of the passed list. ```py def last(lst): diff --git a/snippets/lcm.md b/snippets/lcm.md index 2bcd9a347..2e3b0dc98 100644 --- a/snippets/lcm.md +++ b/snippets/lcm.md @@ -5,7 +5,7 @@ tags: math,list,recursion,advanced Returns the least common multiple of a list of numbers. -Use `functools.reduce()`, `math.gcd()` and `lcm(x,y) = x * y / gcd(x,y)` over the given list. +- Use `functools.reduce()`, `math.gcd()` and `lcm(x,y) = x * y / gcd(x,y)` over the given list. ```py from functools import reduce diff --git a/snippets/longest_item.md b/snippets/longest_item.md index e0add9ebe..d5fe5401e 100644 --- a/snippets/longest_item.md +++ b/snippets/longest_item.md @@ -6,7 +6,7 @@ tags: list,string,intermediate Takes any number of iterable objects or objects with a length property and returns the longest one. If multiple objects have the same length, the first one will be returned. -Use `max()` with `len` as the `key` to return the item with the greatest length. +- Use `max()` with `len` as the `key` to return the item with the greatest length. ```py def longest_item(*args): diff --git a/snippets/map_dictionary.md b/snippets/map_dictionary.md index 8995956ba..0f9633188 100644 --- a/snippets/map_dictionary.md +++ b/snippets/map_dictionary.md @@ -5,7 +5,7 @@ tags: list,intermediate Maps the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value. -Use a `for` loop to iterate over the list's values, assigning the values produced by `fn` to each key of the dictionary. +- Use a `for` loop to iterate over the list's values, assigning the values produced by `fn` to each key of the dictionary. ```py def map_dictionary(itr, fn): diff --git a/snippets/map_values.md b/snippets/map_values.md index 861adc47a..1c58cc61d 100644 --- a/snippets/map_values.md +++ b/snippets/map_values.md @@ -5,7 +5,7 @@ tags: dictionary,function,intermediate Creates a dictionary with the same keys as the provided dictionary and values generated by running the provided function for each value. -Use `dict.keys()` to iterate over the dictionary's keys, assigning the values produced by `fn` to each key of a new dictionary. +- Use `dict.keys()` to iterate over the dictionary's keys, assigning the values produced by `fn` to each key of a new dictionary. ```py def map_values(obj, fn): diff --git a/snippets/max_by.md b/snippets/max_by.md index ae743fa89..8807fc9ce 100644 --- a/snippets/max_by.md +++ b/snippets/max_by.md @@ -5,7 +5,7 @@ tags: math,list,function,beginner Returns the maximum value of a list, after mapping each element to a value using the provided function. -Use `map()` with `fn` to map each element to a value using the provided function, use `max()` to return the maximum value. +- Use `map()` with `fn` to map each element to a value using the provided function, use `max()` to return the maximum value. ```py def max_by(lst, fn): diff --git a/snippets/max_element_index.md b/snippets/max_element_index.md index 1103e6055..563c3d660 100644 --- a/snippets/max_element_index.md +++ b/snippets/max_element_index.md @@ -5,13 +5,13 @@ tags: list,beginner Returns the index of the element with the maximum value in a list. -Use `max()` and `list.index()` to get the maximum value in the list and return its index. +- Use `max()` and `list.index()` to get the maximum value in the list and return its index. ```py def max_element_index(arr): return arr.index(max(arr)) ``` -```python +```py max_element_index([5, 8, 9, 7, 10, 3, 0]) # 4 ``` diff --git a/snippets/max_n.md b/snippets/max_n.md index 3c4ab2d26..ed2111a5f 100644 --- a/snippets/max_n.md +++ b/snippets/max_n.md @@ -6,8 +6,8 @@ tags: list,math,beginner 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 `sorted()` to sort the list, `[:n]` to get the specified number of elements. -Omit the second argument, `n`, to get a one-element list. +- Use `sorted()` to sort the list, `[:n]` to get the specified number of elements. +- Omit the second argument, `n`, to get a one-element list. ```py def max_n(lst, n=1): diff --git a/snippets/median.md b/snippets/median.md index 2cfcb91bc..63119ad66 100644 --- a/snippets/median.md +++ b/snippets/median.md @@ -5,9 +5,8 @@ tags: math,beginner Finds the median of a list of numbers. -Sort the numbers of the list using `list.sort()` and find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even. - -[`statistics.median()`](https://docs.python.org/3/library/statistics.html#statistics.median) provides similar functionality to this snippet. +- Sort the numbers of the list using `list.sort()` and find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even. +- [`statistics.median()`](https://docs.python.org/3/library/statistics.html#statistics.median) provides similar functionality to this snippet. ```py def median(list): diff --git a/snippets/merge.md b/snippets/merge.md index 1d9023af0..61cb65944 100644 --- a/snippets/merge.md +++ b/snippets/merge.md @@ -5,11 +5,10 @@ tags: list,math,advanced Merges two or more lists into a list of lists, combining elements from each of the input lists based on their positions. -Use `max` combined with list comprehension to get the length of the longest list in the arguments. -Use `range()` in combination with the `max_length` variable to loop as many times as there are elements in the longest list. -If a list is shorter than `max_length`, use `fill_value` for the remaining items (defaults to `None`). - -[`zip()`](https://docs.python.org/3/library/functions.html#zip) and [`itertools.zip_longest()`](https://docs.python.org/3/library/itertools.html#itertools.zip_longest) provide similar functionality to this snippet. +- Use `max` combined with list comprehension to get the length of the longest list in the arguments. +- Use `range()` in combination with the `max_length` variable to loop as many times as there are elements in the longest list. +- If a list is shorter than `max_length`, use `fill_value` for the remaining items (defaults to `None`). +- [`zip()`](https://docs.python.org/3/library/functions.html#zip) and [`itertools.zip_longest()`](https://docs.python.org/3/library/itertools.html#itertools.zip_longest) provide similar functionality to this snippet. ```py def merge(*args, fill_value=None): diff --git a/snippets/merge_dictionaries.md b/snippets/merge_dictionaries.md index 7a0ec9b63..34d98f6e7 100644 --- a/snippets/merge_dictionaries.md +++ b/snippets/merge_dictionaries.md @@ -5,7 +5,7 @@ tags: dictionary,intermediate Merges two or more dictionaries. -Create a new `dict()` and loop over `dicts`, using `dictionary.update()` to add the key-value pairs from each one to the result. +- Create a new `dict()` and loop over `dicts`, using `dictionary.update()` to add the key-value pairs from each one to the result. ```py def merge_dictionaries(*dicts): diff --git a/snippets/min_by.md b/snippets/min_by.md index 6147cf953..94380173a 100644 --- a/snippets/min_by.md +++ b/snippets/min_by.md @@ -5,7 +5,7 @@ tags: math,list,function,beginner Returns the minimum value of a list, after mapping each element to a value using the provided function. -Use `map()` with `fn` to map each element to a value using the provided function, use `min()` to return the minimum value. +- Use `map()` with `fn` to map each element to a value using the provided function, use `min()` to return the minimum value. ```py def min_by(lst, fn): diff --git a/snippets/min_n.md b/snippets/min_n.md index 4484c579d..ec2c27330 100644 --- a/snippets/min_n.md +++ b/snippets/min_n.md @@ -6,8 +6,8 @@ tags: list,math,beginner 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 `sorted() to sort the list, `[:n]` to get the specified number of elements. -Omit the second argument, `n`, to get a one-element list. +- Use `sorted() to sort the list, `[:n]` to get the specified number of elements. +- Omit the second argument, `n`, to get a one-element list. ```py def min_n(lst, n=1): diff --git a/snippets/most_frequent.md b/snippets/most_frequent.md index dfdb0cf2c..3d932894d 100644 --- a/snippets/most_frequent.md +++ b/snippets/most_frequent.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the most frequent element in a list. -Use `set(list)` to get the unique values in the `list` combined with `max()` to find the element that has the most appearances. +- Use `set(list)` to get the unique values in the `list` combined with `max()` to find the element that has the most appearances. ```py def most_frequent(list): diff --git a/snippets/n_times_string.md b/snippets/n_times_string.md index 38fcce7b7..71461600b 100644 --- a/snippets/n_times_string.md +++ b/snippets/n_times_string.md @@ -5,7 +5,7 @@ tags: string,beginner Prints out the same string a defined number of times. -Repeat the string `n` times, using the `*` operator. +- Repeat the string `n` times, using the `*` operator. ```py def n_times_string(s, n): diff --git a/snippets/none.md b/snippets/none.md index f6ec47b4b..a86c131c2 100644 --- a/snippets/none.md +++ b/snippets/none.md @@ -5,7 +5,7 @@ tags: list,function,intermediate Returns `False` if the provided function returns `True` for at least one element in the list, `True` otherwise. -Use `all()` and `fn` to check if `fn` returns `False` for all the elements in the list. +- Use `all()` and `fn` to check if `fn` returns `False` for all the elements in the list. ```py def none(lst, fn=lambda x: x): diff --git a/snippets/offset.md b/snippets/offset.md index 783b1cb9c..2ae627530 100644 --- a/snippets/offset.md +++ b/snippets/offset.md @@ -5,7 +5,7 @@ tags: list,beginner Moves the specified amount of elements to the end of the list. -Use `lst[offset:]` and `lst[:offset]` to get the two slices of the list and combine them before returning. +- Use `lst[offset:]` and `lst[:offset]` to get the two slices of the list and combine them before returning. ```py def offset(lst, offset): diff --git a/snippets/palindrome.md b/snippets/palindrome.md index 927689101..e6c9b77bc 100644 --- a/snippets/palindrome.md +++ b/snippets/palindrome.md @@ -5,8 +5,8 @@ tags: string,intermediate Returns `True` if the given string is a palindrome, `False` otherwise. -Use `s.lower()` and `re.sub()` to convert to lowercase and remove non-alphanumeric characters from the given string. -Then, compare the new string with its reverse. +- Use `s.lower()` and `re.sub()` to convert to lowercase and remove non-alphanumeric characters from the given string. +- Then, compare the new string with its reverse. ```py from re import sub diff --git a/snippets/rads_to_degrees.md b/snippets/rads_to_degrees.md index bc2efc3af..3ffecbb24 100644 --- a/snippets/rads_to_degrees.md +++ b/snippets/rads_to_degrees.md @@ -5,7 +5,7 @@ tags: math,beginner Converts an angle from radians to degrees. -Use `math.pi` and the radian to degree formula to convert the angle from radians to degrees. +- Use `math.pi` and the radian to degree formula to convert the angle from radians to degrees. ```py from math import pi diff --git a/snippets/reverse_string.md b/snippets/reverse_string.md index 85ede4309..68478e51f 100644 --- a/snippets/reverse_string.md +++ b/snippets/reverse_string.md @@ -5,7 +5,7 @@ tags: string,beginner Returns the reverse of a string. -Use string slicing to reverse the string. +- Use string slicing to reverse the string. ```py def reverse_string(s): diff --git a/snippets/rgb_to_hex.md b/snippets/rgb_to_hex.md index 15132e904..456ff50e6 100644 --- a/snippets/rgb_to_hex.md +++ b/snippets/rgb_to_hex.md @@ -5,8 +5,8 @@ tags: string,math,intermediate Converts the values of RGB components to a hexadecimal color code. -Create a placeholder for a zero-padded hexadecimal value using `"{:02X}"`, copy it three times. -Use `str.format()` on the resulting string to replace the placeholders with the given values. +- Create a placeholder for a zero-padded hexadecimal value using `"{:02X}"`, copy it three times. +- Use `str.format()` on the resulting string to replace the placeholders with the given values. ```py def rgb_to_hex(r, g, b): diff --git a/snippets/sample.md b/snippets/sample.md index 18eb6b786..f4dd49529 100644 --- a/snippets/sample.md +++ b/snippets/sample.md @@ -5,9 +5,8 @@ tags: list,random,beginner Returns a random element from a list. -Use `random.randint()` to generate a random number that corresponds to an index in the list, return the element at that index. - -[`random.sample()`](https://docs.python.org/3/library/random.html#random.sample) provides similar functionality to this snippet. +- Use `random.randint()` to generate a random number that corresponds to an index in the list, return the element at that index. +- [`random.sample()`](https://docs.python.org/3/library/random.html#random.sample) provides similar functionality to this snippet. ```py from random import randint diff --git a/snippets/shuffle.md b/snippets/shuffle.md index d5ca0ba78..103209a51 100644 --- a/snippets/shuffle.md +++ b/snippets/shuffle.md @@ -5,9 +5,8 @@ tags: list,random,intermediate Randomizes the order of the values of an list, returning a new list. -Uses the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) to reorder the elements of the list. - -[`random.shuffle`](https://docs.python.org/3/library/random.html#random.shuffle) provides similar functionality to this snippet. +- Uses the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) to reorder the elements of the list. +- [`random.shuffle`](https://docs.python.org/3/library/random.html#random.shuffle) provides similar functionality to this snippet. ```py from copy import deepcopy diff --git a/snippets/similarity.md b/snippets/similarity.md index f0d2eb800..d5996cc1a 100644 --- a/snippets/similarity.md +++ b/snippets/similarity.md @@ -5,7 +5,7 @@ tags: list,beginner Returns a list of elements that exist in both lists. -Use list comprehension on `a` to only keep values contained in both lists. +- Use list comprehension on `a` to only keep values contained in both lists. ```py def similarity(a, b): diff --git a/snippets/snake.md b/snippets/snake.md index 95f7e745a..ae67573a4 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -5,7 +5,7 @@ tags: string,regexp,intermediate Converts a string to snake case. -Break the string into words and combine them adding `_` as a separator, using a regexp. +- Break the string into words and combine them adding `_` as a separator, using a regexp. ```py from re import sub diff --git a/snippets/some.md b/snippets/some.md index 6d6e16ef1..25915566f 100644 --- a/snippets/some.md +++ b/snippets/some.md @@ -5,7 +5,7 @@ tags: list,function,intermediate Returns `True` if the provided function returns `True` for at least one element in the list, `False` otherwise. -Use `any()` in combination with `map()` and `fn` to check if `fn` returns `True` for any element in the list. +- Use `any()` in combination with `map()` and `fn` to check if `fn` returns `True` for any element in the list. ```py def some(lst, fn=lambda x: x): diff --git a/snippets/sort_by_indexes.md b/snippets/sort_by_indexes.md index 38539308b..4ee7cdc89 100644 --- a/snippets/sort_by_indexes.md +++ b/snippets/sort_by_indexes.md @@ -5,8 +5,8 @@ tags: list,sort,intermediate Sorts one list based on another list containing the desired indexes. -Use `zip()` and `sorted()` to combine and sort the two lists, based on the values of `indexes`. -Use a list comprehension to get the first element of each pair from the result. +- Use `zip()` and `sorted()` to combine and sort the two lists, based on the values of `indexes`. +- Use a list comprehension to get the first element of each pair from the result. ```py def sort_by_indexes(lst, indexes): diff --git a/snippets/split_lines.md b/snippets/split_lines.md index fdafdb0a0..f0481112b 100644 --- a/snippets/split_lines.md +++ b/snippets/split_lines.md @@ -5,9 +5,8 @@ tags: string,beginner Splits a multiline string into a list of lines. -Use `s.split()` and `'\n'` to match line breaks and create a list. - -[`str.splitlines()`](https://docs.python.org/3/library/stdtypes.html#str.splitlines) provides similar functionality to this snippet. +- Use `s.split()` and `'\n'` to match line breaks and create a list. +- [`str.splitlines()`](https://docs.python.org/3/library/stdtypes.html#str.splitlines) provides similar functionality to this snippet. ```py def split_lines(s): diff --git a/snippets/spread.md b/snippets/spread.md index 07ee43d3a..703091b6e 100644 --- a/snippets/spread.md +++ b/snippets/spread.md @@ -5,7 +5,7 @@ tags: list,intermediate Flattens a list, by spreading its elements into a new list. -Loop over elements, use `list.extend()` if the element is a list, `list.append()` otherwise. +- Loop over elements, use `list.extend()` if the element is a list, `list.append()` otherwise. ```py def spread(arg): diff --git a/snippets/sum_by.md b/snippets/sum_by.md index 2f8078c33..11c7982a6 100644 --- a/snippets/sum_by.md +++ b/snippets/sum_by.md @@ -5,7 +5,7 @@ tags: math,list,function,beginner Returns the sum of a list, after mapping each element to a value using the provided function. -Use `map()` with `fn` to map each element to a value using the provided function, use `sum()` to return the sum of the values. +- Use `map()` with `fn` to map each element to a value using the provided function, use `sum()` to return the sum of the values. ```py def sum_by(lst, fn): diff --git a/snippets/symmetric_difference.md b/snippets/symmetric_difference.md index c6b4e4ab5..5646223ab 100644 --- a/snippets/symmetric_difference.md +++ b/snippets/symmetric_difference.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the symmetric difference between two iterables, without filtering out duplicate values. -Create a `set` from each list, then use list comprehension on each one to only keep values not contained in the previously created set of the other. +- Create a `set` from each list, then use list comprehension on each one to only keep values not contained in the previously created set of the other. ```py def symmetric_difference(a, b): diff --git a/snippets/symmetric_difference_by.md b/snippets/symmetric_difference_by.md index 848ac3fc7..3d7e22f1c 100644 --- a/snippets/symmetric_difference_by.md +++ b/snippets/symmetric_difference_by.md @@ -5,7 +5,7 @@ tags: list,function,intermediate Returns the symmetric difference between two lists, after applying the provided function to each list element of both. -Create a `set` by applying `fn` to each element in every list, then use list comprehension in combination with `fn` on each one to only keep values not contained in the previously created set of the other. +- Create a `set` by applying `fn` to each element in every list, then use list comprehension in combination with `fn` on each one to only keep values not contained in the previously created set of the other. ```py def symmetric_difference_by(a, b, fn): diff --git a/snippets/tail.md b/snippets/tail.md index b3a3d981d..a23277b81 100644 --- a/snippets/tail.md +++ b/snippets/tail.md @@ -5,7 +5,7 @@ tags: list,beginner Returns all elements in a list except for the first one. -Return `lst[1:]` if the list's length is more than `1`, otherwise, return the whole list. +- Return `lst[1:]` if the list's length is more than `1`, otherwise, return the whole list. ```py def tail(lst): diff --git a/snippets/take.md b/snippets/take.md index 6b1f77b7b..c1ae195e8 100644 --- a/snippets/take.md +++ b/snippets/take.md @@ -5,7 +5,7 @@ tags: list,beginner Returns a list with `n` elements removed from the beginning. -Use slice notation to create a slice of the list with `n` elements taken from the beginning. +- Use slice notation to create a slice of the list with `n` elements taken from the beginning. ```py def take(itr, n = 1): diff --git a/snippets/take_right.md b/snippets/take_right.md index 0e68fcbb8..adb0801b3 100644 --- a/snippets/take_right.md +++ b/snippets/take_right.md @@ -5,7 +5,7 @@ tags: list,beginner Returns a list with `n` elements removed from the end. -Use slice notation to create a slice of the list with `n` elements taken from the end. +- Use slice notation to create a slice of the list with `n` elements taken from the end. ```py def take_right(itr, n = 1): diff --git a/snippets/to_dictionary.md b/snippets/to_dictionary.md index d99727872..ecf7e40ff 100644 --- a/snippets/to_dictionary.md +++ b/snippets/to_dictionary.md @@ -6,7 +6,7 @@ tags: list,dictionary,intermediate Combines two lists into a dictionary, where the elements of the first one serve as the keys and the elements of the second one serve as the values. The values of the first list need to be unique and hashable. -Use `zip()` in combination with a list comprehension to combine the values of the two lists, based on their positions. +- Use `zip()` in combination with a list comprehension to combine the values of the two lists, based on their positions. ```py def to_dictionary(keys, values): diff --git a/snippets/transpose.md b/snippets/transpose.md index c9bb8fc59..f8f321d99 100644 --- a/snippets/transpose.md +++ b/snippets/transpose.md @@ -5,8 +5,8 @@ tags: list,intermediate Returns the transpose of a two-dimensional list. -Use `*lst` to get the passed list as tuples. -Use `zip()` in combination with `list()` to create the transpose of the given two-dimensional list. +- Use `*lst` to get the passed list as tuples. +- Use `zip()` in combination with `list()` to create the transpose of the given two-dimensional list. ```py def transpose(lst): diff --git a/snippets/unfold.md b/snippets/unfold.md index a354cc4a8..ecafd4d15 100644 --- a/snippets/unfold.md +++ b/snippets/unfold.md @@ -5,9 +5,9 @@ tags: function,list,advanced Builds a list, using an iterator function and an initial seed value. -The iterator function accepts one argument (`seed`) and must always return a list with two elements ([`value`, `nextSeed`]) or `False` to terminate. -Use a generator function, `fn_generator`, that uses a `while` loop to call the iterator function and `yield` the `value` until it returns `False`. -Use list comprehension to return the list that is produced by the generator, using the iterator function. +- The iterator function accepts one argument (`seed`) and must always return a list with two elements ([`value`, `nextSeed`]) or `False` to terminate. +- Use a generator function, `fn_generator`, that uses a `while` loop to call the iterator function and `yield` the `value` until it returns `False`. +- Use list comprehension to return the list that is produced by the generator, using the iterator function. ```py def unfold(fn, seed): diff --git a/snippets/union.md b/snippets/union.md index 7261b660f..3e52908ab 100644 --- a/snippets/union.md +++ b/snippets/union.md @@ -5,7 +5,7 @@ tags: list,beginner Returns every element that exists in any of the two lists once. -Create a `set` with all values of `a` and `b` and convert to a `list`. +- Create a `set` with all values of `a` and `b` and convert to a `list`. ```py def union(a, b): diff --git a/snippets/union_by.md b/snippets/union_by.md index acc120f63..4ece1bb06 100644 --- a/snippets/union_by.md +++ b/snippets/union_by.md @@ -5,8 +5,8 @@ tags: list,function,intermediate Returns every element that exists in any of the two lists once, after applying the provided function to each element of both. -Create a `set` by applying `fn` to each element in `a`, then use list comprehension in combination with `fn` on `b` to only keep values not contained in the previously created set, `_a`. -Finally, create a `set` from the previous result and `a` and transform it into a `list` +- Create a `set` by applying `fn` to each element in `a`, then use list comprehension in combination with `fn` on `b` to only keep values not contained in the previously created set, `_a`. +- Finally, create a `set` from the previous result and `a` and transform it into a `list` ```py def union_by(a, b, fn): diff --git a/snippets/unique_elements.md b/snippets/unique_elements.md index 6c0c75330..fd21797de 100644 --- a/snippets/unique_elements.md +++ b/snippets/unique_elements.md @@ -5,7 +5,7 @@ tags: list,beginner Returns the unique elements in a given list. -Create a `set` from the list to discard duplicated values, then return a `list` from it. +- Create a `set` from the list to discard duplicated values, then return a `list` from it. ```py def unique_elements(li): diff --git a/snippets/values_only.md b/snippets/values_only.md index f6937412f..13cf189a8 100644 --- a/snippets/values_only.md +++ b/snippets/values_only.md @@ -5,8 +5,8 @@ tags: dictionary,list,beginner Returns a flat list of all the values in a flat dictionary. -Use `dict.values()` to return the values in the given dictionary. -Return a `list()` of the previous result. +- Use `dict.values()` to return the values in the given dictionary. +- Return a `list()` of the previous result. ```py def values_only(flat_dict): diff --git a/snippets/when.md b/snippets/when.md index e45fac3b1..20244a12b 100644 --- a/snippets/when.md +++ b/snippets/when.md @@ -5,7 +5,7 @@ tags: function,intermediate Tests a value, `x`, against a `predicate` function, conditionally applying a function. -Check if the value of `predicate(x)` is `True` and if so return `when_true(x)`, otherwise return `x`. +- Check if the value of `predicate(x)` is `True` and if so return `when_true(x)`, otherwise return `x`. ```py def when(predicate, when_true):