diff --git a/snippets/add_days.md b/snippets/add_days.md index 4bbaf74a5..954e1d72f 100644 --- a/snippets/add_days.md +++ b/snippets/add_days.md @@ -1,6 +1,8 @@ --- title: add_days tags: date,intermediate +firstSeen: 2020-10-28T16:19:04+02:00 +lastUpdated: 2020-10-28T16:19:04+02:00 --- Calculates the date of `n` days from the given date. diff --git a/snippets/all_equal.md b/snippets/all_equal.md index 951561181..79f6d063b 100644 --- a/snippets/all_equal.md +++ b/snippets/all_equal.md @@ -1,6 +1,8 @@ --- title: all_equal tags: list,beginner +firstSeen: 2019-08-20T11:39:18+03:00 +lastUpdated: 2020-10-11T13:40:42+03:00 --- Checks if all elements in a list are equal. diff --git a/snippets/all_unique.md b/snippets/all_unique.md index 5e523c93d..ce7d5c178 100644 --- a/snippets/all_unique.md +++ b/snippets/all_unique.md @@ -1,6 +1,8 @@ --- title: all_unique tags: list,beginner +firstSeen: 2018-04-01T11:03:09+03:00 +lastUpdated: 2021-01-07T23:30:28+02:00 --- Checks if all the values in a list are unique. diff --git a/snippets/arithmetic_progression.md b/snippets/arithmetic_progression.md index a1bda1d90..2fb19fa30 100644 --- a/snippets/arithmetic_progression.md +++ b/snippets/arithmetic_progression.md @@ -1,6 +1,8 @@ --- title: arithmetic_progression tags: math,beginner +firstSeen: 2020-07-28T13:57:33+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Generates a list of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit. diff --git a/snippets/average.md b/snippets/average.md index c3671c753..9d6267dfc 100644 --- a/snippets/average.md +++ b/snippets/average.md @@ -1,6 +1,8 @@ --- title: average tags: math,list,beginner +firstSeen: 2018-01-27T07:16:41+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Calculates the average of two or more numbers. diff --git a/snippets/average_by.md b/snippets/average_by.md index 326c81816..6c4e464ba 100644 --- a/snippets/average_by.md +++ b/snippets/average_by.md @@ -1,6 +1,8 @@ --- title: average_by tags: math,list,intermediate +firstSeen: 2019-08-20T11:55:10+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Calculates the average of a list, after mapping each element to a value using the provided function. diff --git a/snippets/bifurcate.md b/snippets/bifurcate.md index 9ccc89e9e..0092af1e6 100644 --- a/snippets/bifurcate.md +++ b/snippets/bifurcate.md @@ -1,6 +1,8 @@ --- title: bifurcate tags: list,intermediate +firstSeen: 2019-08-20T12:37:06+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Splits values into two groups, based on the result of the given `filter` list. diff --git a/snippets/bifurcate_by.md b/snippets/bifurcate_by.md index 2b6847575..6d6fefcd9 100644 --- a/snippets/bifurcate_by.md +++ b/snippets/bifurcate_by.md @@ -1,6 +1,8 @@ --- title: bifurcate_by tags: list,intermediate +firstSeen: 2019-08-20T12:41:21+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Splits values into two groups, based on the result of the given filtering function. diff --git a/snippets/binomial_coefficient.md b/snippets/binomial_coefficient.md index 153d0bbb0..e33f64c0c 100644 --- a/snippets/binomial_coefficient.md +++ b/snippets/binomial_coefficient.md @@ -1,6 +1,8 @@ --- title: binomial_coefficient tags: math,beginner +firstSeen: 2020-10-04T11:56:31+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Calculates the number of ways to choose `k` items from `n` items without repetition and without order. diff --git a/snippets/byte_size.md b/snippets/byte_size.md index 447ad3560..3d992cce5 100644 --- a/snippets/byte_size.md +++ b/snippets/byte_size.md @@ -1,6 +1,8 @@ --- title: byte_size tags: string,beginner +firstSeen: 2018-02-01T10:19:59+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Returns the length of a string in bytes. diff --git a/snippets/camel.md b/snippets/camel.md index dbfbc8e1a..b79248151 100644 --- a/snippets/camel.md +++ b/snippets/camel.md @@ -1,6 +1,8 @@ --- title: camel tags: string,regexp,intermediate +firstSeen: 2019-08-21T08:59:54+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Converts a string to camelcase. diff --git a/snippets/capitalize.md b/snippets/capitalize.md index 238de044f..0e38e70d8 100644 --- a/snippets/capitalize.md +++ b/snippets/capitalize.md @@ -1,6 +1,8 @@ --- title: capitalize tags: string,intermediate +firstSeen: 2018-02-01T10:19:59+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Capitalizes the first letter of a string. diff --git a/snippets/capitalize_every_word.md b/snippets/capitalize_every_word.md index 132067955..784d4b6ca 100644 --- a/snippets/capitalize_every_word.md +++ b/snippets/capitalize_every_word.md @@ -1,6 +1,8 @@ --- title: capitalize_every_word tags: string,beginner +firstSeen: 2018-02-01T10:19:59+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Capitalizes the first letter of every word in a string. diff --git a/snippets/cast_list.md b/snippets/cast_list.md index cb5854b8c..d077c0ef8 100644 --- a/snippets/cast_list.md +++ b/snippets/cast_list.md @@ -1,6 +1,8 @@ --- title: cast_list tags: list,intermediate +firstSeen: 2019-08-20T12:47:43+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Casts the provided value as a list if it's not one. diff --git a/snippets/celsius_to_fahrenheit.md b/snippets/celsius_to_fahrenheit.md index 58a6fd56b..39aac29b4 100644 --- a/snippets/celsius_to_fahrenheit.md +++ b/snippets/celsius_to_fahrenheit.md @@ -1,18 +1,20 @@ ---- -title: celsius_to_fahrenheit -tags: math,beginner -unlisted: true ---- - -Converts Celsius to Fahrenheit. - -- Follow the conversion formula `F = 1.8 * C + 32`. - -```py -def celsius_to_fahrenheit(degrees): - return ((degrees * 1.8) + 32) -``` - -```py -celsius_to_fahrenheit(180) # 356.0 -``` +--- +title: celsius_to_fahrenheit +tags: math,beginner +unlisted: true +firstSeen: 2020-04-05T12:29:03+03:00 +lastUpdated: 2021-01-04T12:47:04+02:00 +--- + +Converts Celsius to Fahrenheit. + +- Follow the conversion formula `F = 1.8 * C + 32`. + +```py +def celsius_to_fahrenheit(degrees): + return ((degrees * 1.8) + 32) +``` + +```py +celsius_to_fahrenheit(180) # 356.0 +``` diff --git a/snippets/check_prop.md b/snippets/check_prop.md index 2c27ddd26..dff5991f8 100644 --- a/snippets/check_prop.md +++ b/snippets/check_prop.md @@ -1,19 +1,21 @@ ---- -title: check_prop -tags: function,intermediate ---- - -Creates a function that will invoke a predicate function for the specified property on a given object. - -- Return a `lambda` function that takes an object and applies the predicate function, `fn` to the specified property. - -```py -def check_prop(fn, prop): - return lambda obj: fn(obj[prop]) -``` - -```py -check_age = check_prop(lambda x: x >= 18, 'age') -user = {'name': 'Mark', 'age': 18} -check_age(user) # True -``` +--- +title: check_prop +tags: function,intermediate +firstSeen: 2020-01-02T16:49:25+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 +--- + +Creates a function that will invoke a predicate function for the specified property on a given object. + +- Return a `lambda` function that takes an object and applies the predicate function, `fn` to the specified property. + +```py +def check_prop(fn, prop): + return lambda obj: fn(obj[prop]) +``` + +```py +check_age = check_prop(lambda x: x >= 18, 'age') +user = {'name': 'Mark', 'age': 18} +check_age(user) # True +``` diff --git a/snippets/chunk.md b/snippets/chunk.md index 8e11567e9..b6c584289 100644 --- a/snippets/chunk.md +++ b/snippets/chunk.md @@ -1,6 +1,8 @@ --- title: chunk tags: list,intermediate +firstSeen: 2018-01-09T06:39:42+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Chunks a list into smaller lists of a specified size. diff --git a/snippets/chunk_into_n.md b/snippets/chunk_into_n.md index 1fe4df135..211c53f72 100644 --- a/snippets/chunk_into_n.md +++ b/snippets/chunk_into_n.md @@ -1,6 +1,8 @@ --- title: chunk_into_n tags: list,intermediate +firstSeen: 2020-10-12T22:11:30+03:00 +lastUpdated: 2020-10-23T05:35:06+03:00 --- Chunks a list into `n` smaller lists. diff --git a/snippets/clamp_number.md b/snippets/clamp_number.md index 2304cfc28..ba17926fe 100644 --- a/snippets/clamp_number.md +++ b/snippets/clamp_number.md @@ -1,6 +1,8 @@ --- title: clamp_number tags: math,beginner +firstSeen: 2019-08-20T12:50:38+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Clamps `num` within the inclusive range specified by the boundary values. diff --git a/snippets/collect_dictionary.md b/snippets/collect_dictionary.md index 90d37aad2..d380b6d73 100644 --- a/snippets/collect_dictionary.md +++ b/snippets/collect_dictionary.md @@ -1,6 +1,8 @@ --- title: collect_dictionary tags: dictionary,intermediate +firstSeen: 2020-04-07T21:15:06+03:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Inverts a dictionary with non-unique hashable values. diff --git a/snippets/combine_values.md b/snippets/combine_values.md index 01d2c7c1f..4164e6cfb 100644 --- a/snippets/combine_values.md +++ b/snippets/combine_values.md @@ -1,28 +1,30 @@ ---- -title: combine_values -tags: dictionary,intermediate ---- - -Combines two or more dictionaries, creating a list of values for each key. - -- Create a new `collections.defaultdict` with `list` as the default value for each key and loop over `dicts`. -- Use `dict.append()` to map the values of the dictionary to keys. -- Use `dict()` to convert the `collections.defaultdict` to a regular dictionary. - -```py -from collections import defaultdict - -def combine_values(*dicts): - res = defaultdict(list) - for d in dicts: - for key in d: - res[key].append(d[key]) - return dict(res) -``` - -```py -d1 = {'a': 1, 'b': 'foo', 'c': 400} -d2 = {'a': 3, 'b': 200, 'd': 400} - -combine_values(d1, d2) # {'a': [1, 3], 'b': ['foo', 200], 'c': [400], 'd': [400]} -``` +--- +title: combine_values +tags: dictionary,intermediate +firstSeen: 2021-03-07T12:30:47+02:00 +lastUpdated: 2021-04-04T14:32:35+03:00 +--- + +Combines two or more dictionaries, creating a list of values for each key. + +- Create a new `collections.defaultdict` with `list` as the default value for each key and loop over `dicts`. +- Use `dict.append()` to map the values of the dictionary to keys. +- Use `dict()` to convert the `collections.defaultdict` to a regular dictionary. + +```py +from collections import defaultdict + +def combine_values(*dicts): + res = defaultdict(list) + for d in dicts: + for key in d: + res[key].append(d[key]) + return dict(res) +``` + +```py +d1 = {'a': 1, 'b': 'foo', 'c': 400} +d2 = {'a': 3, 'b': 200, 'd': 400} + +combine_values(d1, d2) # {'a': [1, 3], 'b': ['foo', 200], 'c': [400], 'd': [400]} +``` diff --git a/snippets/compact.md b/snippets/compact.md index ee4239abe..ad3d06673 100644 --- a/snippets/compact.md +++ b/snippets/compact.md @@ -1,6 +1,8 @@ --- title: compact tags: list,beginner +firstSeen: 2018-01-19T12:17:06+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- Removes falsy values from a list. diff --git a/snippets/compose.md b/snippets/compose.md index 0221c42bc..d4401050d 100644 --- a/snippets/compose.md +++ b/snippets/compose.md @@ -1,23 +1,25 @@ ---- -title: compose -tags: function,advanced ---- - -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. - -```py -from functools import reduce - -def compose(*fns): - return reduce(lambda f, g: lambda *args: f(g(*args)), fns) -``` - -```py -add5 = lambda x: x + 5 -multiply = lambda x, y: x * y -multiply_and_add_5 = compose(add5, multiply) -multiply_and_add_5(5, 2) # 15 -``` +--- +title: compose +tags: function,advanced +firstSeen: 2020-01-02T15:51:20+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 +--- + +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. + +```py +from functools import reduce + +def compose(*fns): + return reduce(lambda f, g: lambda *args: f(g(*args)), fns) +``` + +```py +add5 = lambda x: x + 5 +multiply = lambda x, y: x * y +multiply_and_add_5 = compose(add5, multiply) +multiply_and_add_5(5, 2) # 15 +``` diff --git a/snippets/compose_right.md b/snippets/compose_right.md index dfc472599..73a2ee1a9 100644 --- a/snippets/compose_right.md +++ b/snippets/compose_right.md @@ -1,23 +1,25 @@ ---- -title: compose_right -tags: function,advanced ---- - -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. - -```py -from functools import reduce - -def compose_right(*fns): - return reduce(lambda f, g: lambda *args: g(f(*args)), fns) -``` - -```py -add = lambda x, y: x + y -square = lambda x: x * x -add_and_square = compose_right(add, square) -add_and_square(1, 2) # 9 -``` +--- +title: compose_right +tags: function,advanced +firstSeen: 2020-01-02T15:51:26+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 +--- + +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. + +```py +from functools import reduce + +def compose_right(*fns): + return reduce(lambda f, g: lambda *args: g(f(*args)), fns) +``` + +```py +add = lambda x, y: x + y +square = lambda x: x * x +add_and_square = compose_right(add, square) +add_and_square(1, 2) # 9 +``` diff --git a/snippets/count_by.md b/snippets/count_by.md index b9102d2eb..6c0ffdf02 100644 --- a/snippets/count_by.md +++ b/snippets/count_by.md @@ -1,6 +1,8 @@ --- title: count_by tags: list,intermediate +firstSeen: 2018-02-07T10:33:47+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 --- 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_occurrences.md b/snippets/count_occurrences.md index 130b62771..2dc413583 100644 --- a/snippets/count_occurrences.md +++ b/snippets/count_occurrences.md @@ -1,6 +1,8 @@ --- title: count_occurrences tags: list,beginner +firstSeen: 2021-01-10T00:00:36+02:00 +lastUpdated: 2021-01-10T00:00:36+02:00 --- Counts the occurrences of a value in a list. diff --git a/snippets/cumsum.md b/snippets/cumsum.md index a70846283..3c8fa7794 100644 --- a/snippets/cumsum.md +++ b/snippets/cumsum.md @@ -1,20 +1,22 @@ ---- -title: cumsum -tags: list,intermediate ---- - -Creates a list of partial sums. - -- Use `itertools.accumulate()` to create the accumulated sum for each element. -- Use `list()` to convert the result into a list. - -```py -from itertools import accumulate - -def cumsum(lst): - return list(accumulate(lst)) -``` - -```py -cumsum(range(0, 15, 3)) # [0, 3, 9, 18, 30] -``` +--- +title: cumsum +tags: list,intermediate +firstSeen: 2021-01-13T23:30:41+02:00 +lastUpdated: 2021-01-13T23:30:41+02:00 +--- + +Creates a list of partial sums. + +- Use `itertools.accumulate()` to create the accumulated sum for each element. +- Use `list()` to convert the result into a list. + +```py +from itertools import accumulate + +def cumsum(lst): + return list(accumulate(lst)) +``` + +```py +cumsum(range(0, 15, 3)) # [0, 3, 9, 18, 30] +``` diff --git a/snippets/curry.md b/snippets/curry.md index 025ff9720..1e232a70b 100644 --- a/snippets/curry.md +++ b/snippets/curry.md @@ -1,21 +1,23 @@ ---- -title: curry -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. - -```py -from functools import partial - -def curry(fn, *args): - return partial(fn, *args) -``` - -```py -add = lambda x, y: x + y -add10 = curry(add, 10) -add10(20) # 30 -``` +--- +title: curry +tags: function,intermediate +firstSeen: 2020-01-02T16:14:50+02:00 +lastUpdated: 2020-11-02T19:27:07+02:00 +--- + +Curries a function. + +- 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 + +def curry(fn, *args): + return partial(fn, *args) +``` + +```py +add = lambda x, y: x + y +add10 = curry(add, 10) +add10(20) # 30 +``` diff --git a/snippets/daterange.md b/snippets/daterange.md index 56c4d3429..994e0f88a 100644 --- a/snippets/daterange.md +++ b/snippets/daterange.md @@ -1,6 +1,8 @@ --- title: daterange tags: date,intermediate +firstSeen: 2020-10-28T16:19:14+02:00 +lastUpdated: 2021-01-07T23:30:28+02:00 --- Creates a list of dates between `start` (inclusive) and `end` (not inclusive). diff --git a/snippets/days_ago.md b/snippets/days_ago.md index c75fca4a1..1cbb0ac9a 100644 --- a/snippets/days_ago.md +++ b/snippets/days_ago.md @@ -1,6 +1,8 @@ --- title: days_ago tags: date,intermediate +firstSeen: 2020-10-28T16:19:30+02:00 +lastUpdated: 2020-10-28T16:19:30+02:00 --- Calculates the date of `n` days ago from today. diff --git a/snippets/days_diff.md b/snippets/days_diff.md index d2ce985f0..2374169fc 100644 --- a/snippets/days_diff.md +++ b/snippets/days_diff.md @@ -1,6 +1,8 @@ --- title: days_diff tags: date,beginner +firstSeen: 2020-10-28T16:19:39+02:00 +lastUpdated: 2020-10-28T16:19:39+02:00 --- Calculates the day difference between two dates. diff --git a/snippets/days_from_now.md b/snippets/days_from_now.md index 79ccfd7a6..35a4c801d 100644 --- a/snippets/days_from_now.md +++ b/snippets/days_from_now.md @@ -1,6 +1,8 @@ --- title: days_from_now tags: date,intermediate +firstSeen: 2020-10-28T16:19:51+02:00 +lastUpdated: 2020-10-28T16:19:51+02:00 --- Calculates the date of `n` days from today. diff --git a/snippets/decapitalize.md b/snippets/decapitalize.md index c68a93d6b..dd43c2a5c 100644 --- a/snippets/decapitalize.md +++ b/snippets/decapitalize.md @@ -1,6 +1,8 @@ --- title: decapitalize tags: string,intermediate +firstSeen: 2018-02-01T10:19:59+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Decapitalizes the first letter of a string. diff --git a/snippets/deep_flatten.md b/snippets/deep_flatten.md index 7c6822bb3..0b35872be 100644 --- a/snippets/deep_flatten.md +++ b/snippets/deep_flatten.md @@ -1,6 +1,8 @@ --- title: deep_flatten tags: list,recursion,intermediate +firstSeen: 2018-01-16T16:54:14+02:00 +lastUpdated: 2020-12-29T19:53:45+02:00 --- Deep flattens a list. diff --git a/snippets/degrees_to_rads.md b/snippets/degrees_to_rads.md index 5426d459f..3bb652523 100644 --- a/snippets/degrees_to_rads.md +++ b/snippets/degrees_to_rads.md @@ -1,6 +1,8 @@ --- title: degrees_to_rads tags: math,beginner +firstSeen: 2019-10-15T14:31:11+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Converts an angle from degrees to radians. diff --git a/snippets/delay.md b/snippets/delay.md index 70f4f3b7b..722a4f3f6 100644 --- a/snippets/delay.md +++ b/snippets/delay.md @@ -1,20 +1,22 @@ ---- -title: delay -tags: function,intermediate ---- - -Invokes the provided function after `ms` milliseconds. - -- Use `time.sleep()` to delay the execution of `fn` by `ms / 1000` seconds. - -```py -from time import sleep - -def delay(fn, ms, *args): - sleep(ms / 1000) - return fn(*args) -``` - -```py -delay(lambda x: print(x), 1000, 'later') # prints 'later' after one second -``` +--- +title: delay +tags: function,intermediate +firstSeen: 2020-01-02T16:24:51+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Invokes the provided function after `ms` milliseconds. + +- Use `time.sleep()` to delay the execution of `fn` by `ms / 1000` seconds. + +```py +from time import sleep + +def delay(fn, ms, *args): + sleep(ms / 1000) + return fn(*args) +``` + +```py +delay(lambda x: print(x), 1000, 'later') # prints 'later' after one second +``` diff --git a/snippets/dict_to_list.md b/snippets/dict_to_list.md index 5b13d7365..1ea0a2d48 100644 --- a/snippets/dict_to_list.md +++ b/snippets/dict_to_list.md @@ -1,6 +1,8 @@ --- title: dict_to_list tags: dictionary,list,intermediate +firstSeen: 2020-10-16T21:24:14+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Converts a dictionary to a list of tuples. diff --git a/snippets/difference.md b/snippets/difference.md index cd34674f3..aece687fa 100644 --- a/snippets/difference.md +++ b/snippets/difference.md @@ -1,6 +1,8 @@ --- title: difference tags: list,beginner +firstSeen: 2018-01-20T16:16:44+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Calculates the difference between two iterables, without filtering duplicate values. diff --git a/snippets/difference_by.md b/snippets/difference_by.md index c436dd037..f28234eda 100644 --- a/snippets/difference_by.md +++ b/snippets/difference_by.md @@ -1,6 +1,8 @@ --- title: difference_by tags: list,function,intermediate +firstSeen: 2018-02-08T15:59:27+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Returns the difference between two lists, after applying the provided function to each list element of both. diff --git a/snippets/digitize.md b/snippets/digitize.md index fed9b46bf..2e22c5f8c 100644 --- a/snippets/digitize.md +++ b/snippets/digitize.md @@ -1,6 +1,8 @@ --- title: digitize tags: math,list,beginner +firstSeen: 2019-08-20T13:00:27+03:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Converts a number to a list of digits. diff --git a/snippets/drop.md b/snippets/drop.md index 3770c4ef4..14a6ab8aa 100644 --- a/snippets/drop.md +++ b/snippets/drop.md @@ -1,20 +1,22 @@ ---- -title: drop -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. -- Omit the last argument, `n`, to use a default value of `1`. - -```py -def drop(a, n = 1): - return a[n:] -``` - -```py -drop([1, 2, 3]) # [2, 3] -drop([1, 2, 3], 2) # [3] -drop([1, 2, 3], 42) # [] -``` +--- +title: drop +tags: list,beginner +firstSeen: 2020-03-10T21:59:41+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Returns a list with `n` elements removed from the left. + +- Use slice notation to remove the specified number of elements from the left. +- Omit the last argument, `n`, to use a default value of `1`. + +```py +def drop(a, n = 1): + return a[n:] +``` + +```py +drop([1, 2, 3]) # [2, 3] +drop([1, 2, 3], 2) # [3] +drop([1, 2, 3], 42) # [] +``` diff --git a/snippets/drop_right.md b/snippets/drop_right.md index 5dd30b2cb..465e47a46 100644 --- a/snippets/drop_right.md +++ b/snippets/drop_right.md @@ -1,20 +1,22 @@ ---- -title: drop_right -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. -- Omit the last argument, `n`, to use a default value of `1`. - -```py -def drop_right(a, n = 1): - return a[:-n] -``` - -```py -drop_right([1, 2, 3]) # [1, 2] -drop_right([1, 2, 3], 2) # [1] -drop_right([1, 2, 3], 42) # [] -``` +--- +title: drop_right +tags: list,beginner +firstSeen: 2020-03-10T21:59:41+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Returns a list with `n` elements removed from the right. + +- Use slice notation to remove the specified number of elements from the right. +- Omit the last argument, `n`, to use a default value of `1`. + +```py +def drop_right(a, n = 1): + return a[:-n] +``` + +```py +drop_right([1, 2, 3]) # [1, 2] +drop_right([1, 2, 3], 2) # [1] +drop_right([1, 2, 3], 42) # [] +``` diff --git a/snippets/every.md b/snippets/every.md index 48fe9f39c..1d667267f 100644 --- a/snippets/every.md +++ b/snippets/every.md @@ -1,6 +1,8 @@ --- title: every tags: list,intermediate +firstSeen: 2019-08-20T11:34:24+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Checks if the provided function returns `True` for every element in the list. diff --git a/snippets/every_nth.md b/snippets/every_nth.md index a20711d70..74840ef89 100644 --- a/snippets/every_nth.md +++ b/snippets/every_nth.md @@ -1,6 +1,8 @@ --- title: every_nth tags: list,beginner +firstSeen: 2019-08-20T13:10:12+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Returns every `nth` element in a list. diff --git a/snippets/factorial.md b/snippets/factorial.md index c5bcbb2e0..d0cd8c9cc 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -1,6 +1,8 @@ --- title: factorial tags: math,recursion,beginner +firstSeen: 2018-01-27T07:29:56+02:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Calculates the factorial of a number. diff --git a/snippets/fahrenheit_to_celsius.md b/snippets/fahrenheit_to_celsius.md index 77a09e53e..a37f63340 100644 --- a/snippets/fahrenheit_to_celsius.md +++ b/snippets/fahrenheit_to_celsius.md @@ -1,18 +1,20 @@ ---- -title: fahrenheit_to_celsius -tags: math,beginner -unlisted: true ---- - -Converts Fahrenheit to Celsius. - -- Follow the conversion formula `C = (F - 32) * 5/9`. - -```py -def fahrenheit_to_celsius(degrees): - return ((degrees - 32) * 5/9) -``` - -```py -fahrenheit_to_celsius(77) # 25.0 -``` +--- +title: fahrenheit_to_celsius +tags: math,beginner +unlisted: true +firstSeen: 2020-04-05T12:29:03+03:00 +lastUpdated: 2021-01-04T12:47:04+02:00 +--- + +Converts Fahrenheit to Celsius. + +- Follow the conversion formula `C = (F - 32) * 5/9`. + +```py +def fahrenheit_to_celsius(degrees): + return ((degrees - 32) * 5/9) +``` + +```py +fahrenheit_to_celsius(77) # 25.0 +``` diff --git a/snippets/fibonacci.md b/snippets/fibonacci.md index 7de53c697..c57356a5d 100644 --- a/snippets/fibonacci.md +++ b/snippets/fibonacci.md @@ -1,24 +1,26 @@ ---- -title: fibonacci -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`. - -```py -def fibonacci(n): - if n <= 0: - return [0] - sequence = [0, 1] - while len(sequence) <= n: - next_value = sequence[len(sequence) - 1] + sequence[len(sequence) - 2] - sequence.append(next_value) - return sequence -``` - -```py -fibonacci(7) # [0, 1, 1, 2, 3, 5, 8, 13] -``` +--- +title: fibonacci +tags: math,list,intermediate +firstSeen: 2018-10-06T06:06:33+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +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`. + +```py +def fibonacci(n): + if n <= 0: + return [0] + sequence = [0, 1] + while len(sequence) <= n: + next_value = sequence[len(sequence) - 1] + sequence[len(sequence) - 2] + sequence.append(next_value) + return sequence +``` + +```py +fibonacci(7) # [0, 1, 1, 2, 3, 5, 8, 13] +``` diff --git a/snippets/filter_non_unique.md b/snippets/filter_non_unique.md index ac8178ce3..9c9f5d634 100644 --- a/snippets/filter_non_unique.md +++ b/snippets/filter_non_unique.md @@ -1,6 +1,8 @@ --- title: filter_non_unique tags: list,beginner +firstSeen: 2019-08-20T13:13:51+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Creates a list with the non-unique values filtered out. diff --git a/snippets/filter_unique.md b/snippets/filter_unique.md index a4f9697d7..f5d8c3fe7 100644 --- a/snippets/filter_unique.md +++ b/snippets/filter_unique.md @@ -1,6 +1,8 @@ --- title: filter_unique tags: list,beginner +firstSeen: 2019-10-02T20:06:24+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Creates a list with the unique values filtered out. diff --git a/snippets/find.md b/snippets/find.md index ac2c2f467..89b05bf1e 100644 --- a/snippets/find.md +++ b/snippets/find.md @@ -1,17 +1,19 @@ ---- -title: find -tags: list,beginner ---- - -Finds the value of the first element in the given list that satisfies the provided testing function. - -- Use a list comprehension and `next()` to return the first element in `lst` for which `fn` returns `True`. - -```py -def find(lst, fn): - return next(x for x in lst if fn(x)) -``` - -```py -find([1, 2, 3, 4], lambda n: n % 2 == 1) # 1 -``` +--- +title: find +tags: list,beginner +firstSeen: 2020-03-10T22:38:48+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Finds the value of the first element in the given list that satisfies the provided testing function. + +- Use a list comprehension and `next()` to return the first element in `lst` for which `fn` returns `True`. + +```py +def find(lst, fn): + return next(x for x in lst if fn(x)) +``` + +```py +find([1, 2, 3, 4], lambda n: n % 2 == 1) # 1 +``` diff --git a/snippets/find_index.md b/snippets/find_index.md index 4ceac691a..2bf44ac4a 100644 --- a/snippets/find_index.md +++ b/snippets/find_index.md @@ -1,17 +1,19 @@ ---- -title: find_index -tags: list,intermediate ---- - -Finds the index of the first element in the given list that satisfies the provided testing function. - -- Use a 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): - return next(i for i, x in enumerate(lst) if fn(x)) -``` - -```py -find_index([1, 2, 3, 4], lambda n: n % 2 == 1) # 0 -``` +--- +title: find_index +tags: list,intermediate +firstSeen: 2020-03-10T22:38:48+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Finds the index of the first element in the given list that satisfies the provided testing function. + +- Use a 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): + return next(i for i, x in enumerate(lst) if fn(x)) +``` + +```py +find_index([1, 2, 3, 4], lambda n: n % 2 == 1) # 0 +``` diff --git a/snippets/find_index_of_all.md b/snippets/find_index_of_all.md index 6bcda46a8..5701135de 100644 --- a/snippets/find_index_of_all.md +++ b/snippets/find_index_of_all.md @@ -1,6 +1,8 @@ --- title: find_index_of_all tags: list,intermediate +firstSeen: 2020-10-11T13:45:19+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Finds the indexes of all elements in the given list that satisfy the provided testing function. diff --git a/snippets/find_key.md b/snippets/find_key.md index cd837fed9..b95fbb0bf 100644 --- a/snippets/find_key.md +++ b/snippets/find_key.md @@ -1,6 +1,8 @@ --- title: find_key tags: dictionary,intermediate +firstSeen: 2020-04-16T19:13:20+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Finds the first key in the provided dictionary that has the given value. diff --git a/snippets/find_keys.md b/snippets/find_keys.md index dc1fb098e..63256dd1d 100644 --- a/snippets/find_keys.md +++ b/snippets/find_keys.md @@ -1,6 +1,8 @@ --- title: find_keys tags: dictionary,intermediate +firstSeen: 2020-04-16T19:17:13+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Finds all keys in the provided dictionary that have the given value. diff --git a/snippets/find_last.md b/snippets/find_last.md index 9ead95a75..bbab175b2 100644 --- a/snippets/find_last.md +++ b/snippets/find_last.md @@ -1,17 +1,19 @@ ---- -title: find_last -tags: list,beginner ---- - -Finds the value of the last element in the given list that satisfies the provided testing function. - -- Use a list comprehension and `next()` to return the last element in `lst` for which `fn` returns `True`. - -```py -def find_last(lst, fn): - return next(x for x in lst[::-1] if fn(x)) -``` - -```py -find_last([1, 2, 3, 4], lambda n: n % 2 == 1) # 3 -``` +--- +title: find_last +tags: list,beginner +firstSeen: 2020-03-10T22:38:48+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Finds the value of the last element in the given list that satisfies the provided testing function. + +- Use a list comprehension and `next()` to return the last element in `lst` for which `fn` returns `True`. + +```py +def find_last(lst, fn): + return next(x for x in lst[::-1] if fn(x)) +``` + +```py +find_last([1, 2, 3, 4], lambda n: n % 2 == 1) # 3 +``` diff --git a/snippets/find_last_index.md b/snippets/find_last_index.md index 369f71d60..9e87007e5 100644 --- a/snippets/find_last_index.md +++ b/snippets/find_last_index.md @@ -1,17 +1,19 @@ ---- -title: find_last_index -tags: list,beginner ---- - -Finds the index of the last element in the given list that satisfies the provided testing function. - -- Use a 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): - return len(lst) - 1 - next(i for i, x in enumerate(lst[::-1]) if fn(x)) -``` - -```py -find_last_index([1, 2, 3, 4], lambda n: n % 2 == 1) # 2 -``` +--- +title: find_last_index +tags: list,beginner +firstSeen: 2020-03-10T22:38:48+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Finds the index of the last element in the given list that satisfies the provided testing function. + +- Use a 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): + return len(lst) - 1 - next(i for i, x in enumerate(lst[::-1]) if fn(x)) +``` + +```py +find_last_index([1, 2, 3, 4], lambda n: n % 2 == 1) # 2 +``` diff --git a/snippets/find_parity_outliers.md b/snippets/find_parity_outliers.md index f90a9719a..f53d44a0f 100644 --- a/snippets/find_parity_outliers.md +++ b/snippets/find_parity_outliers.md @@ -1,6 +1,8 @@ --- title: find_parity_outliers tags: list,math,intermediate +firstSeen: 2020-01-08T18:54:35+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Finds the items that are parity outliers in a given list. diff --git a/snippets/flatten.md b/snippets/flatten.md index ff11b6726..b220c86c3 100644 --- a/snippets/flatten.md +++ b/snippets/flatten.md @@ -1,6 +1,8 @@ --- title: flatten tags: list,intermediate +firstSeen: 2019-09-19T15:46:10+03:00 +lastUpdated: 2020-11-02T19:27:53+02:00 --- Flattens a list of lists once. diff --git a/snippets/for_each.md b/snippets/for_each.md index 16bb81070..5a95e9e31 100644 --- a/snippets/for_each.md +++ b/snippets/for_each.md @@ -1,18 +1,20 @@ ---- -title: for_each -tags: list,beginner ---- - -Executes the provided function once for each list element. - -- Use a `for` loop to execute `fn` for each element in `itr`. - -```py -def for_each(itr, fn): - for el in itr: - fn(el) -``` - -```py -for_each([1, 2, 3], print) # 1 2 3 -``` +--- +title: for_each +tags: list,beginner +firstSeen: 2020-03-15T12:54:08+02:00 +lastUpdated: 2020-09-15T16:13:06+03:00 +--- + +Executes the provided function once for each list element. + +- Use a `for` loop to execute `fn` for each element in `itr`. + +```py +def for_each(itr, fn): + for el in itr: + fn(el) +``` + +```py +for_each([1, 2, 3], print) # 1 2 3 +``` diff --git a/snippets/for_each_right.md b/snippets/for_each_right.md index 819172931..be899ad37 100644 --- a/snippets/for_each_right.md +++ b/snippets/for_each_right.md @@ -1,18 +1,20 @@ ---- -title: for_each_right -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. - -```py -def for_each_right(itr, fn): - for el in itr[::-1]: - fn(el) -``` - -```py -for_each_right([1, 2, 3], print) # 3 2 1 -``` +--- +title: for_each_right +tags: list,beginner +firstSeen: 2020-03-15T12:54:08+02:00 +lastUpdated: 2020-09-15T16:13:06+03:00 +--- + +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. + +```py +def for_each_right(itr, fn): + for el in itr[::-1]: + fn(el) +``` + +```py +for_each_right([1, 2, 3], print) # 3 2 1 +``` diff --git a/snippets/frequencies.md b/snippets/frequencies.md index 6786a8983..0922c9210 100644 --- a/snippets/frequencies.md +++ b/snippets/frequencies.md @@ -1,23 +1,25 @@ ---- -title: frequencies -tags: list,intermediate ---- - -Creates a dictionary with the unique values of a list as keys and their frequencies as the values. - -- Use `collections.defaultdict()` to store the frequencies of each unique element. -- Use `dict()` to return a dictionary with the unique elements of the list as keys and their frequencies as the values. - -```py -from collections import defaultdict - -def frequencies(lst): - freq = defaultdict(int) - for val in lst: - freq[val] += 1 - return dict(freq) -``` - -```py -frequencies(['a', 'b', 'a', 'c', 'a', 'a', 'b']) # { 'a': 4, 'b': 2, 'c': 1 } -``` +--- +title: frequencies +tags: list,intermediate +firstSeen: 2020-03-15T12:54:08+02:00 +lastUpdated: 2020-11-02T19:27:53+02:00 +--- + +Creates a dictionary with the unique values of a list as keys and their frequencies as the values. + +- Use `collections.defaultdict()` to store the frequencies of each unique element. +- Use `dict()` to return a dictionary with the unique elements of the list as keys and their frequencies as the values. + +```py +from collections import defaultdict + +def frequencies(lst): + freq = defaultdict(int) + for val in lst: + freq[val] += 1 + return dict(freq) +``` + +```py +frequencies(['a', 'b', 'a', 'c', 'a', 'a', 'b']) # { 'a': 4, 'b': 2, 'c': 1 } +``` diff --git a/snippets/from_iso_date.md b/snippets/from_iso_date.md index d43d85c6f..ca22ecf75 100644 --- a/snippets/from_iso_date.md +++ b/snippets/from_iso_date.md @@ -1,6 +1,8 @@ --- title: from_iso_date tags: date,intermediate +firstSeen: 2020-10-28T16:20:04+02:00 +lastUpdated: 2021-01-07T23:30:28+02:00 --- Converts a date from its ISO-8601 representation. diff --git a/snippets/gcd.md b/snippets/gcd.md index 57a637044..f0f36a7f8 100644 --- a/snippets/gcd.md +++ b/snippets/gcd.md @@ -1,6 +1,8 @@ --- title: gcd tags: math,beginner +firstSeen: 2018-01-08T16:26:35+02:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Calculates the greatest common divisor of a list of numbers. diff --git a/snippets/geometric_progression.md b/snippets/geometric_progression.md index 752768b86..e426ecd7c 100644 --- a/snippets/geometric_progression.md +++ b/snippets/geometric_progression.md @@ -1,6 +1,8 @@ --- title: geometric_progression tags: math,list,intermediate +firstSeen: 2020-10-04T12:19:28+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Initializes a list containing the numbers in the specified range where `start` and `end` are inclusive and the ratio between two terms is `step`. diff --git a/snippets/get.md b/snippets/get.md index 4c0cfaa62..3c0080c46 100644 --- a/snippets/get.md +++ b/snippets/get.md @@ -1,6 +1,8 @@ --- title: get tags: dictionary,list,intermediate +firstSeen: 2020-10-28T12:21:39+02:00 +lastUpdated: 2020-10-28T12:21:39+02:00 --- Retrieves the value of the nested key indicated by the given selector list from a dictionary or list. diff --git a/snippets/group_by.md b/snippets/group_by.md index b7e030243..ca9ee3c19 100644 --- a/snippets/group_by.md +++ b/snippets/group_by.md @@ -1,6 +1,8 @@ --- title: group_by tags: list,dictionary,intermediate +firstSeen: 2019-08-20T13:29:00+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Groups the elements of a list based on the given function. diff --git a/snippets/hamming_distance.md b/snippets/hamming_distance.md index 2e46b3d24..a78c83d70 100644 --- a/snippets/hamming_distance.md +++ b/snippets/hamming_distance.md @@ -1,19 +1,21 @@ ---- -title: hamming_distance -tags: math,intermediate ---- - -Calculates the Hamming distance between two values. - -- Use the XOR operator (`^`) to find the bit difference between the two numbers. -- Use `bin()` to convert the result to a binary string. -- Convert the string to a list and use `count()` of `str` class to count and return the number of `1`s in it. - -```py -def hamming_distance(a, b): - return bin(a ^ b).count('1') -``` - -```py -hamming_distance(2, 3) # 1 -``` +--- +title: hamming_distance +tags: math,intermediate +firstSeen: 2021-01-17T13:04:06+02:00 +lastUpdated: 2021-02-18T14:22:25+02:00 +--- + +Calculates the Hamming distance between two values. + +- Use the XOR operator (`^`) to find the bit difference between the two numbers. +- Use `bin()` to convert the result to a binary string. +- Convert the string to a list and use `count()` of `str` class to count and return the number of `1`s in it. + +```py +def hamming_distance(a, b): + return bin(a ^ b).count('1') +``` + +```py +hamming_distance(2, 3) # 1 +``` diff --git a/snippets/has_duplicates.md b/snippets/has_duplicates.md index a088344de..c8ee94f12 100644 --- a/snippets/has_duplicates.md +++ b/snippets/has_duplicates.md @@ -1,6 +1,8 @@ --- title: has_duplicates tags: list,beginner +firstSeen: 2018-04-01T11:03:09+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Checks if there are duplicate values in a flat list. diff --git a/snippets/have_same_contents.md b/snippets/have_same_contents.md index 16d352926..7da8726f4 100644 --- a/snippets/have_same_contents.md +++ b/snippets/have_same_contents.md @@ -1,22 +1,24 @@ ---- -title: have_same_contents -tags: list,intermediate ---- - -Checks if two lists contain the same elements regardless of order. - -- 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): - for v in set(a + b): - if a.count(v) != b.count(v): - return False - return True -``` - -```py -have_same_contents([1, 2, 4], [2, 4, 1]) # True -``` +--- +title: have_same_contents +tags: list,intermediate +firstSeen: 2020-03-15T12:54:08+02:00 +lastUpdated: 2020-11-02T19:28:05+02:00 +--- + +Checks if two lists contain the same elements regardless of order. + +- 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): + for v in set(a + b): + if a.count(v) != b.count(v): + return False + return True +``` + +```py +have_same_contents([1, 2, 4], [2, 4, 1]) # True +``` diff --git a/snippets/head.md b/snippets/head.md index 4102080ca..4e8d17bcc 100644 --- a/snippets/head.md +++ b/snippets/head.md @@ -1,6 +1,8 @@ --- title: head tags: list,beginner +firstSeen: 2019-08-20T14:08:52+03:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Returns the head of a list. diff --git a/snippets/hex_to_rgb.md b/snippets/hex_to_rgb.md index 1771d7085..d13af2c24 100644 --- a/snippets/hex_to_rgb.md +++ b/snippets/hex_to_rgb.md @@ -1,6 +1,8 @@ --- title: hex_to_rgb tags: string,math,intermediate +firstSeen: 2020-09-13T01:08:21+03:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components. diff --git a/snippets/in_range.md b/snippets/in_range.md index 97583523a..2b30bffae 100644 --- a/snippets/in_range.md +++ b/snippets/in_range.md @@ -1,6 +1,8 @@ --- title: in_range tags: math,beginner +firstSeen: 2019-08-20T13:41:40+03:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Checks if the given number falls within the given range. diff --git a/snippets/includes_all.md b/snippets/includes_all.md index f102f423f..fdb5b8fbc 100644 --- a/snippets/includes_all.md +++ b/snippets/includes_all.md @@ -1,22 +1,24 @@ ---- -title: includes_all -tags: list,intermediate ---- - -Checks if all the elements in `values` are included in `lst`. - -- Check if every value in `values` is contained in `lst` using a `for` loop. -- Return `False` if any one value is not found, `True` otherwise. - -```py -def includes_all(lst, values): - for v in values: - if v not in lst: - return False - return True -``` - -```py -includes_all([1, 2, 3, 4], [1, 4]) # True -includes_all([1, 2, 3, 4], [1, 5]) # False -``` +--- +title: includes_all +tags: list,intermediate +firstSeen: 2020-03-15T12:54:08+02:00 +lastUpdated: 2020-11-02T19:28:05+02:00 +--- + +Checks if all the elements in `values` are included in `lst`. + +- Check if every value in `values` is contained in `lst` using a `for` loop. +- Return `False` if any one value is not found, `True` otherwise. + +```py +def includes_all(lst, values): + for v in values: + if v not in lst: + return False + return True +``` + +```py +includes_all([1, 2, 3, 4], [1, 4]) # True +includes_all([1, 2, 3, 4], [1, 5]) # False +``` diff --git a/snippets/includes_any.md b/snippets/includes_any.md index aef0d8e9d..e1310ab53 100644 --- a/snippets/includes_any.md +++ b/snippets/includes_any.md @@ -1,22 +1,24 @@ ---- -title: includes_any -tags: list,intermediate ---- - -Checks if any element in `values` is included in `lst`. - -- Check if any value in `values` is contained in `lst` using a `for` loop. -- Return `True` if any one value is found, `False` otherwise. - -```py -def includes_any(lst, values): - for v in values: - if v in lst: - return True - return False -``` - -```py -includes_any([1, 2, 3, 4], [2, 9]) # True -includes_any([1, 2, 3, 4], [8, 9]) # False -``` +--- +title: includes_any +tags: list,intermediate +firstSeen: 2020-03-15T12:54:08+02:00 +lastUpdated: 2020-11-02T19:28:05+02:00 +--- + +Checks if any element in `values` is included in `lst`. + +- Check if any value in `values` is contained in `lst` using a `for` loop. +- Return `True` if any one value is found, `False` otherwise. + +```py +def includes_any(lst, values): + for v in values: + if v in lst: + return True + return False +``` + +```py +includes_any([1, 2, 3, 4], [2, 9]) # True +includes_any([1, 2, 3, 4], [8, 9]) # False +``` diff --git a/snippets/index_of_all.md b/snippets/index_of_all.md index 08ba78fe9..0460427b3 100644 --- a/snippets/index_of_all.md +++ b/snippets/index_of_all.md @@ -1,6 +1,8 @@ --- title: index_of_all tags: list,intermediate +firstSeen: 2020-10-11T13:40:42+03:00 +lastUpdated: 2020-10-11T13:45:19+03:00 --- Returns a list of indexes of all the occurrences of an element in a list. diff --git a/snippets/initial.md b/snippets/initial.md index 2afa69374..a11f27c00 100644 --- a/snippets/initial.md +++ b/snippets/initial.md @@ -1,6 +1,8 @@ --- title: initial tags: list,beginner +firstSeen: 2019-08-20T14:08:52+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Returns all the elements of a list except the last one. diff --git a/snippets/initialize_2d_list.md b/snippets/initialize_2d_list.md index a98aac79d..df9514269 100644 --- a/snippets/initialize_2d_list.md +++ b/snippets/initialize_2d_list.md @@ -1,6 +1,8 @@ --- title: initialize_2d_list tags: list,intermediate +firstSeen: 2019-10-25T10:11:51+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Initializes a 2D list of given width and height and value. diff --git a/snippets/initialize_list_with_range.md b/snippets/initialize_list_with_range.md index f126a41f5..bc4501916 100644 --- a/snippets/initialize_list_with_range.md +++ b/snippets/initialize_list_with_range.md @@ -1,6 +1,8 @@ --- title: initialize_list_with_range tags: list,beginner +firstSeen: 2019-08-20T15:21:41+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Initializes a list containing the numbers in the specified range where `start` and `end` are inclusive with their common difference `step`. diff --git a/snippets/initialize_list_with_values.md b/snippets/initialize_list_with_values.md index 6fe5aab73..9d8715fed 100644 --- a/snippets/initialize_list_with_values.md +++ b/snippets/initialize_list_with_values.md @@ -1,6 +1,8 @@ --- title: initialize_list_with_values tags: list,beginner +firstSeen: 2019-08-20T14:12:06+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Initializes and fills a list with the specified value. diff --git a/snippets/intersection.md b/snippets/intersection.md index 5a1766023..6d1a18996 100644 --- a/snippets/intersection.md +++ b/snippets/intersection.md @@ -1,6 +1,8 @@ --- title: intersection tags: list,beginner +firstSeen: 2019-08-20T15:14:26+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Returns a list of elements that exist in both lists. diff --git a/snippets/intersection_by.md b/snippets/intersection_by.md index ceedde049..5ad79f54c 100644 --- a/snippets/intersection_by.md +++ b/snippets/intersection_by.md @@ -1,6 +1,8 @@ --- title: intersection_by tags: list,function,intermediate +firstSeen: 2019-08-20T15:16:27+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Returns a list of elements that exist in both lists, after applying the provided function to each list element of both. diff --git a/snippets/invert_dictionary.md b/snippets/invert_dictionary.md index e8c3a37aa..0f0b9e23f 100644 --- a/snippets/invert_dictionary.md +++ b/snippets/invert_dictionary.md @@ -1,6 +1,8 @@ --- title: invert_dictionary tags: dictionary,intermediate +firstSeen: 2020-04-07T21:13:32+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Inverts a dictionary with unique hashable values. diff --git a/snippets/is_anagram.md b/snippets/is_anagram.md index c84a38c1e..733e022c8 100644 --- a/snippets/is_anagram.md +++ b/snippets/is_anagram.md @@ -1,6 +1,8 @@ --- title: is_anagram tags: string,intermediate +firstSeen: 2018-10-01T13:17:29+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters). diff --git a/snippets/is_contained_in.md b/snippets/is_contained_in.md index 6db48c412..76d1a3718 100644 --- a/snippets/is_contained_in.md +++ b/snippets/is_contained_in.md @@ -1,21 +1,23 @@ ---- -title: is_contained_in -tags: list,intermediate ---- - -Checks if the elements of the first list are contained in the second one regardless of order. - -- Use `count()` to check if any value in `a` has more occurrences than it has in `b`. -- Return `False` if any such value is found, `True` otherwise. - -```py -def is_contained_in(a, b): - for v in set(a): - if a.count(v) > b.count(v): - return False - return True -``` - -```py -is_contained_in([1, 4], [2, 4, 1]) # True -``` +--- +title: is_contained_in +tags: list,intermediate +firstSeen: 2020-03-16T19:48:15+02:00 +lastUpdated: 2021-01-07T23:30:28+02:00 +--- + +Checks if the elements of the first list are contained in the second one regardless of order. + +- Use `count()` to check if any value in `a` has more occurrences than it has in `b`. +- Return `False` if any such value is found, `True` otherwise. + +```py +def is_contained_in(a, b): + for v in set(a): + if a.count(v) > b.count(v): + return False + return True +``` + +```py +is_contained_in([1, 4], [2, 4, 1]) # True +``` diff --git a/snippets/is_divisible.md b/snippets/is_divisible.md index 33c668408..36ea7d4cd 100644 --- a/snippets/is_divisible.md +++ b/snippets/is_divisible.md @@ -2,6 +2,8 @@ title: is_divisible tags: math,beginner unlisted: true +firstSeen: 2019-08-20T14:19:55+03:00 +lastUpdated: 2021-01-04T12:47:04+02:00 --- Checks if the first numeric argument is divisible by the second one. diff --git a/snippets/is_even.md b/snippets/is_even.md index 32ab8a84e..f8997c655 100644 --- a/snippets/is_even.md +++ b/snippets/is_even.md @@ -2,6 +2,8 @@ title: is_even tags: math,beginner unlisted: true +firstSeen: 2019-08-20T14:21:44+03:00 +lastUpdated: 2021-01-04T12:47:04+02:00 --- Checks if the given number is even. diff --git a/snippets/is_odd.md b/snippets/is_odd.md index 4519d4ce6..cc4559b48 100644 --- a/snippets/is_odd.md +++ b/snippets/is_odd.md @@ -2,6 +2,8 @@ title: is_odd tags: math,beginner unlisted: true +firstSeen: 2019-08-20T14:21:44+03:00 +lastUpdated: 2021-01-04T12:47:04+02:00 --- Checks if the given number is odd. diff --git a/snippets/is_prime.md b/snippets/is_prime.md index 1e2bf61e6..9eac36c2e 100644 --- a/snippets/is_prime.md +++ b/snippets/is_prime.md @@ -1,6 +1,8 @@ --- title: is_prime tags: math,intermediate +firstSeen: 2020-10-03T18:03:32+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Checks if the provided integer is a prime number. diff --git a/snippets/is_weekday.md b/snippets/is_weekday.md index da0b6b55e..68c77c725 100644 --- a/snippets/is_weekday.md +++ b/snippets/is_weekday.md @@ -1,6 +1,8 @@ --- title: is_weekday tags: date,beginner +firstSeen: 2020-10-28T16:20:18+02:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Checks if the given date is a weekday. diff --git a/snippets/is_weekend.md b/snippets/is_weekend.md index 8e7d0aa01..ab141c969 100644 --- a/snippets/is_weekend.md +++ b/snippets/is_weekend.md @@ -1,6 +1,8 @@ --- title: is_weekend tags: date,beginner +firstSeen: 2020-10-28T16:20:27+02:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Checks if the given date is a weekend. diff --git a/snippets/kebab.md b/snippets/kebab.md index 32caf503b..50cf2602a 100644 --- a/snippets/kebab.md +++ b/snippets/kebab.md @@ -1,6 +1,8 @@ --- title: kebab tags: string,regexp,intermediate +firstSeen: 2019-08-21T08:59:54+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Converts a string to kebab case. diff --git a/snippets/key_in_dict.md b/snippets/key_in_dict.md index 24c33423f..81dd8093d 100644 --- a/snippets/key_in_dict.md +++ b/snippets/key_in_dict.md @@ -1,6 +1,8 @@ --- title: key_in_dict tags: dictionary,beginner +firstSeen: 2020-10-16T21:30:49+03:00 +lastUpdated: 2020-10-16T21:30:49+03:00 --- Checks if the given key exists in a dictionary. diff --git a/snippets/key_of_max.md b/snippets/key_of_max.md index 6d1b56e5d..dd760cb41 100644 --- a/snippets/key_of_max.md +++ b/snippets/key_of_max.md @@ -1,17 +1,19 @@ ---- -title: key_of_max -tags: dictionary,beginner ---- - -Finds the key of the maximum value in a dictionary. - -- Use `max()` with the `key` parameter set to `dict.get()` to find and return the key of the maximum value in the given dictionary. - -```py -def key_of_max(d): - return max(d, key = d.get) -``` - -```py -key_of_max({'a':4, 'b':0, 'c':13}) # c -``` +--- +title: key_of_max +tags: dictionary,beginner +firstSeen: 2021-01-07T23:15:48+02:00 +lastUpdated: 2021-01-07T23:15:48+02:00 +--- + +Finds the key of the maximum value in a dictionary. + +- Use `max()` with the `key` parameter set to `dict.get()` to find and return the key of the maximum value in the given dictionary. + +```py +def key_of_max(d): + return max(d, key = d.get) +``` + +```py +key_of_max({'a':4, 'b':0, 'c':13}) # c +``` diff --git a/snippets/key_of_min.md b/snippets/key_of_min.md index f39ad5f27..402e5c519 100644 --- a/snippets/key_of_min.md +++ b/snippets/key_of_min.md @@ -1,17 +1,19 @@ ---- -title: key_of_min -tags: dictionary,beginner ---- - -Finds the key of the minimum value in a dictionary. - -- Use `min()` with the `key` parameter set to `dict.get()` to find and return the key of the minimum value in the given dictionary. - -```py -def key_of_min(d): - return min(d, key = d.get) -``` - -```py -key_of_min({'a':4, 'b':0, 'c':13}) # b -``` +--- +title: key_of_min +tags: dictionary,beginner +firstSeen: 2021-01-07T23:15:48+02:00 +lastUpdated: 2021-01-07T23:15:48+02:00 +--- + +Finds the key of the minimum value in a dictionary. + +- Use `min()` with the `key` parameter set to `dict.get()` to find and return the key of the minimum value in the given dictionary. + +```py +def key_of_min(d): + return min(d, key = d.get) +``` + +```py +key_of_min({'a':4, 'b':0, 'c':13}) # b +``` diff --git a/snippets/keys_only.md b/snippets/keys_only.md index f7c1c5fc2..138f67837 100644 --- a/snippets/keys_only.md +++ b/snippets/keys_only.md @@ -1,6 +1,8 @@ --- title: keys_only tags: dictionary,list,beginner +firstSeen: 2018-04-01T23:56:31+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Creates a flat list of all the keys in a flat dictionary. diff --git a/snippets/km_to_miles.md b/snippets/km_to_miles.md index b094d5799..c371fa544 100644 --- a/snippets/km_to_miles.md +++ b/snippets/km_to_miles.md @@ -2,6 +2,8 @@ title: km_to_miles tags: math,beginner unlisted: true +firstSeen: 2020-10-04T00:23:49+03:00 +lastUpdated: 2021-01-04T12:47:04+02:00 --- Converts kilometers to miles. diff --git a/snippets/last.md b/snippets/last.md index c8bd073b9..4baebaa01 100644 --- a/snippets/last.md +++ b/snippets/last.md @@ -1,6 +1,8 @@ --- title: last tags: list,beginner +firstSeen: 2019-08-20T15:11:47+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Returns the last element in a list. diff --git a/snippets/lcm.md b/snippets/lcm.md index 6b82acc1d..1817eb26f 100644 --- a/snippets/lcm.md +++ b/snippets/lcm.md @@ -1,6 +1,8 @@ --- title: lcm tags: math,list,intermediate +firstSeen: 2018-01-08T22:30:17+02:00 +lastUpdated: 2020-11-02T19:31:15+02:00 --- Returns the least common multiple of a list of numbers. diff --git a/snippets/longest_item.md b/snippets/longest_item.md index cf3ad527e..020da40bf 100644 --- a/snippets/longest_item.md +++ b/snippets/longest_item.md @@ -1,6 +1,8 @@ --- title: longest_item tags: list,string,intermediate +firstSeen: 2019-08-20T15:27:49+03:00 +lastUpdated: 2020-11-02T19:28:05+02:00 --- Takes any number of iterable objects or objects with a length property and returns the longest one. diff --git a/snippets/map_dictionary.md b/snippets/map_dictionary.md index 7cf6adc9a..b1a69a361 100644 --- a/snippets/map_dictionary.md +++ b/snippets/map_dictionary.md @@ -1,6 +1,8 @@ --- title: map_dictionary tags: list,dictionary,intermediate +firstSeen: 2020-04-07T19:53:48+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- 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. diff --git a/snippets/map_values.md b/snippets/map_values.md index ec40971cb..92be4ce49 100644 --- a/snippets/map_values.md +++ b/snippets/map_values.md @@ -1,6 +1,8 @@ --- title: map_values tags: dictionary,intermediate +firstSeen: 2019-08-20T15:34:30+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Creates a dictionary with the same keys as the provided dictionary and values generated by running the provided function for each value. diff --git a/snippets/max_by.md b/snippets/max_by.md index 1d619d9de..f49f5d20b 100644 --- a/snippets/max_by.md +++ b/snippets/max_by.md @@ -1,6 +1,8 @@ --- title: max_by tags: math,list,beginner +firstSeen: 2019-08-20T15:42:41+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Returns the maximum value of a list, after mapping each element to a value using the provided function. diff --git a/snippets/max_element_index.md b/snippets/max_element_index.md index fc9d02a8f..13acfb3d2 100644 --- a/snippets/max_element_index.md +++ b/snippets/max_element_index.md @@ -1,17 +1,19 @@ ---- -title: max_element_index -tags: math,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. - -```py -def max_element_index(arr): - return arr.index(max(arr)) -``` - -```py -max_element_index([5, 8, 9, 7, 10, 3, 0]) # 4 -``` +--- +title: max_element_index +tags: math,list,beginner +firstSeen: 2019-10-31T09:42:21+02:00 +lastUpdated: 2020-11-02T19:28:27+02:00 +--- + +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. + +```py +def max_element_index(arr): + return arr.index(max(arr)) +``` + +```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 9e1269c16..1958b1cc0 100644 --- a/snippets/max_n.md +++ b/snippets/max_n.md @@ -1,6 +1,8 @@ --- title: max_n tags: list,math,beginner +firstSeen: 2018-01-19T11:25:28+02:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Returns the `n` maximum elements from the provided list. diff --git a/snippets/median.md b/snippets/median.md index d329ab88a..428f0875d 100644 --- a/snippets/median.md +++ b/snippets/median.md @@ -1,6 +1,8 @@ --- title: median tags: math,beginner +firstSeen: 2019-10-03T12:02:17+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Finds the median of a list of numbers. diff --git a/snippets/merge.md b/snippets/merge.md index 5e200ebaa..3f2c08df7 100644 --- a/snippets/merge.md +++ b/snippets/merge.md @@ -1,6 +1,8 @@ --- title: merge tags: list,advanced +firstSeen: 2020-04-13T19:09:12+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Merges two or more lists into a list of lists, combining elements from each of the input lists based on their positions. diff --git a/snippets/merge_dictionaries.md b/snippets/merge_dictionaries.md index a0d18f47b..d6f640de3 100644 --- a/snippets/merge_dictionaries.md +++ b/snippets/merge_dictionaries.md @@ -1,6 +1,8 @@ --- title: merge_dictionaries tags: dictionary,intermediate +firstSeen: 2020-04-16T19:28:35+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Merges two or more dictionaries. diff --git a/snippets/miles_to_km.md b/snippets/miles_to_km.md index 140b48b0a..f10fcd38c 100644 --- a/snippets/miles_to_km.md +++ b/snippets/miles_to_km.md @@ -2,6 +2,8 @@ title: miles_to_km tags: math,beginner unlisted: true +firstSeen: 2020-10-04T00:24:01+03:00 +lastUpdated: 2021-01-04T12:47:04+02:00 --- Converts miles to kilometers. diff --git a/snippets/min_by.md b/snippets/min_by.md index 289aba7ed..c6ae5ab9d 100644 --- a/snippets/min_by.md +++ b/snippets/min_by.md @@ -1,6 +1,8 @@ --- title: min_by tags: math,list,beginner +firstSeen: 2019-08-20T15:42:41+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Returns the minimum value of a list, after mapping each element to a value using the provided function. diff --git a/snippets/min_element_index.md b/snippets/min_element_index.md index 279f30d17..41765a5ee 100644 --- a/snippets/min_element_index.md +++ b/snippets/min_element_index.md @@ -1,6 +1,8 @@ --- title: min_element_index tags: math,list,beginner +firstSeen: 2020-10-05T22:32:00+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Returns the index of the element with the minimum value in a list. diff --git a/snippets/min_n.md b/snippets/min_n.md index dccf3ad24..d7ee9243f 100644 --- a/snippets/min_n.md +++ b/snippets/min_n.md @@ -1,6 +1,8 @@ --- title: min_n tags: list,math,beginner +firstSeen: 2018-01-19T11:25:28+02:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Returns the `n` minimum elements from the provided list. diff --git a/snippets/months_diff.md b/snippets/months_diff.md index 4c8a70e3e..4506c4459 100644 --- a/snippets/months_diff.md +++ b/snippets/months_diff.md @@ -1,6 +1,8 @@ --- title: months_diff tags: date,beginner +firstSeen: 2020-10-28T16:20:39+02:00 +lastUpdated: 2020-10-28T16:20:39+02:00 --- Calculates the month difference between two dates. diff --git a/snippets/most_frequent.md b/snippets/most_frequent.md index fea931a72..06c76c1dc 100644 --- a/snippets/most_frequent.md +++ b/snippets/most_frequent.md @@ -1,6 +1,8 @@ --- title: most_frequent tags: list,beginner +firstSeen: 2019-10-12T00:40:49+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Returns the most frequent element in a list. diff --git a/snippets/n_times_string.md b/snippets/n_times_string.md index 0a995a7b6..ee75a0fc3 100644 --- a/snippets/n_times_string.md +++ b/snippets/n_times_string.md @@ -1,17 +1,19 @@ ---- -title: n_times_string -tags: string,beginner ---- - -Generates a string with the given string value repeated `n` number of times. - -- Repeat the string `n` times, using the `*` operator. - -```py -def n_times_string(s, n): - return (s * n) -``` - -```py -n_times_string('py', 4) #'pypypypy' -``` +--- +title: n_times_string +tags: string,beginner +firstSeen: 2019-09-27T10:07:25+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 +--- + +Generates a string with the given string value repeated `n` number of times. + +- Repeat the string `n` times, using the `*` operator. + +```py +def n_times_string(s, n): + return (s * n) +``` + +```py +n_times_string('py', 4) #'pypypypy' +``` diff --git a/snippets/none.md b/snippets/none.md index 019aa1aa0..7b64d0272 100644 --- a/snippets/none.md +++ b/snippets/none.md @@ -1,6 +1,8 @@ --- title: none tags: list,intermediate +firstSeen: 2019-08-20T15:54:50+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Checks if the provided function returns `True` for at least one element in the list. diff --git a/snippets/num_to_range.md b/snippets/num_to_range.md index 30f045837..b83dcc8c0 100644 --- a/snippets/num_to_range.md +++ b/snippets/num_to_range.md @@ -1,6 +1,8 @@ --- title: num_to_range tags: math,beginner +firstSeen: 2020-10-04T12:43:57+03:00 +lastUpdated: 2021-04-05T18:25:46+03:00 --- Maps a number from one range to another range. diff --git a/snippets/offset.md b/snippets/offset.md index ef1132f73..787bcc1e2 100644 --- a/snippets/offset.md +++ b/snippets/offset.md @@ -1,6 +1,8 @@ --- title: offset tags: list,beginner +firstSeen: 2019-08-20T15:53:15+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Moves the specified amount of elements to the end of the list. diff --git a/snippets/pad.md b/snippets/pad.md index 8a9f70214..964c07391 100644 --- a/snippets/pad.md +++ b/snippets/pad.md @@ -1,22 +1,24 @@ ---- -title: pad -tags: string,beginner ---- - -Pads a string on both sides with the specified character, if it's shorter than the specified length. - -- Use `str.ljust()` and `str.rjust()` to pad both sides of the given string. -- Omit the third argument, `char`, to use the whitespace character as the default padding character. - -```py -from math import floor - -def pad(s, length, char = ' '): - return s.rjust(floor((len(s) + length)/2), char).ljust(length, char) -``` - -```py -pad('cat', 8) # ' cat ' -pad('42', 6, '0') # '004200' -pad('foobar', 3) # 'foobar' -``` +--- +title: pad +tags: string,beginner +firstSeen: 2020-10-04T01:53:05+03:00 +lastUpdated: 2020-10-04T01:53:05+03:00 +--- + +Pads a string on both sides with the specified character, if it's shorter than the specified length. + +- Use `str.ljust()` and `str.rjust()` to pad both sides of the given string. +- Omit the third argument, `char`, to use the whitespace character as the default padding character. + +```py +from math import floor + +def pad(s, length, char = ' '): + return s.rjust(floor((len(s) + length)/2), char).ljust(length, char) +``` + +```py +pad('cat', 8) # ' cat ' +pad('42', 6, '0') # '004200' +pad('foobar', 3) # 'foobar' +``` diff --git a/snippets/pad_number.md b/snippets/pad_number.md index b96f1d7d3..767725662 100644 --- a/snippets/pad_number.md +++ b/snippets/pad_number.md @@ -1,6 +1,8 @@ --- title: pad_number tags: string,math,beginner +firstSeen: 2020-10-04T01:42:19+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Pads a given number to the specified length. diff --git a/snippets/palindrome.md b/snippets/palindrome.md index 9ce5cf975..faf920b94 100644 --- a/snippets/palindrome.md +++ b/snippets/palindrome.md @@ -1,6 +1,8 @@ --- title: palindrome tags: string,intermediate +firstSeen: 2018-02-01T10:19:59+02:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Checks if the given string is a palindrome. diff --git a/snippets/pluck.md b/snippets/pluck.md index 492023412..dd08a8714 100644 --- a/snippets/pluck.md +++ b/snippets/pluck.md @@ -1,23 +1,25 @@ ---- -title: pluck -tags: list,dictionary,beginner ---- - -Converts a list of dictionaries into a list of values corresponding to the specified `key`. - -- Use a list comprehension and `dict.get()` to get the value of `key` for each dictionary in `lst`. - -```py -def pluck(lst, key): - return [x.get(key) for x in lst] -``` - -```py -simpsons = [ - { 'name': 'lisa', 'age': 8 }, - { 'name': 'homer', 'age': 36 }, - { 'name': 'marge', 'age': 34 }, - { 'name': 'bart', 'age': 10 } -] -pluck(simpsons, 'age') # [8, 36, 34, 10] -``` +--- +title: pluck +tags: list,dictionary,beginner +firstSeen: 2020-10-22T03:49:25+03:00 +lastUpdated: 2020-10-22T10:09:44+03:00 +--- + +Converts a list of dictionaries into a list of values corresponding to the specified `key`. + +- Use a list comprehension and `dict.get()` to get the value of `key` for each dictionary in `lst`. + +```py +def pluck(lst, key): + return [x.get(key) for x in lst] +``` + +```py +simpsons = [ + { 'name': 'lisa', 'age': 8 }, + { 'name': 'homer', 'age': 36 }, + { 'name': 'marge', 'age': 34 }, + { 'name': 'bart', 'age': 10 } +] +pluck(simpsons, 'age') # [8, 36, 34, 10] +``` diff --git a/snippets/powerset.md b/snippets/powerset.md index 181301f5f..c43241e06 100644 --- a/snippets/powerset.md +++ b/snippets/powerset.md @@ -1,22 +1,24 @@ ---- -title: powerset -tags: math,list,advanced ---- - -Returns the powerset of a given iterable. - -- Use `list()` to convert the given value to a list. -- Use `range()` and `itertools.combinations()` to create a generator that returns all subsets. -- Use `itertools.chain.from_iterable()` and `list()` to consume the generator and return a list. - -```py -from itertools import chain, combinations - -def powerset(iterable): - s = list(iterable) - return list(chain.from_iterable(combinations(s, r) for r in range(len(s)+1))) -``` - -```py -powerset([1, 2]) # [(), (1,), (2,), (1, 2)] -``` +--- +title: powerset +tags: math,list,advanced +firstSeen: 2020-10-04T13:14:01+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 +--- + +Returns the powerset of a given iterable. + +- Use `list()` to convert the given value to a list. +- Use `range()` and `itertools.combinations()` to create a generator that returns all subsets. +- Use `itertools.chain.from_iterable()` and `list()` to consume the generator and return a list. + +```py +from itertools import chain, combinations + +def powerset(iterable): + s = list(iterable) + return list(chain.from_iterable(combinations(s, r) for r in range(len(s)+1))) +``` + +```py +powerset([1, 2]) # [(), (1,), (2,), (1, 2)] +``` diff --git a/snippets/rads_to_degrees.md b/snippets/rads_to_degrees.md index a0c6b0334..845382391 100644 --- a/snippets/rads_to_degrees.md +++ b/snippets/rads_to_degrees.md @@ -1,6 +1,8 @@ --- title: rads_to_degrees tags: math,beginner +firstSeen: 2019-08-20T15:58:57+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Converts an angle from radians to degrees. diff --git a/snippets/reverse.md b/snippets/reverse.md index 8c19c1791..6586b1b70 100644 --- a/snippets/reverse.md +++ b/snippets/reverse.md @@ -1,6 +1,8 @@ --- title: reverse tags: list,string,beginner +firstSeen: 2020-10-06T19:02:30+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Reverses a list or a string. diff --git a/snippets/reverse_number.md b/snippets/reverse_number.md index ccbe8e662..63e693f90 100644 --- a/snippets/reverse_number.md +++ b/snippets/reverse_number.md @@ -1,6 +1,8 @@ --- title: reverse_number tags: math,intermediate +firstSeen: 2020-10-04T14:21:41+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Reverses a number. diff --git a/snippets/rgb_to_hex.md b/snippets/rgb_to_hex.md index 749952459..b007dc09d 100644 --- a/snippets/rgb_to_hex.md +++ b/snippets/rgb_to_hex.md @@ -1,6 +1,8 @@ --- title: rgb_to_hex tags: string,math,intermediate +firstSeen: 2020-09-13T01:08:00+03:00 +lastUpdated: 2020-11-02T19:28:27+02:00 --- Converts the values of RGB components to a hexadecimal color code. diff --git a/snippets/roll.md b/snippets/roll.md index fbfe3c643..7def092c0 100644 --- a/snippets/roll.md +++ b/snippets/roll.md @@ -1,6 +1,8 @@ --- title: roll tags: list,beginner +firstSeen: 2020-11-02T19:15:44+02:00 +lastUpdated: 2020-11-02T19:15:44+02:00 --- Moves the specified amount of elements to the start of the list. diff --git a/snippets/sample.md b/snippets/sample.md index d8f43d0ea..05a6a2f18 100644 --- a/snippets/sample.md +++ b/snippets/sample.md @@ -1,6 +1,8 @@ --- title: sample tags: list,random,beginner +firstSeen: 2019-08-20T16:02:37+03:00 +lastUpdated: 2020-10-28T11:45:34+02:00 --- Returns a random element from a list. diff --git a/snippets/shuffle.md b/snippets/shuffle.md index 5c6c1fbbf..1a84c129b 100644 --- a/snippets/shuffle.md +++ b/snippets/shuffle.md @@ -1,6 +1,8 @@ --- title: shuffle tags: list,random,advanced +firstSeen: 2018-01-19T11:59:33+02:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Randomizes the order of the values of an list, returning a new list. diff --git a/snippets/similarity.md b/snippets/similarity.md index 7c3d3e117..3eb5706b3 100644 --- a/snippets/similarity.md +++ b/snippets/similarity.md @@ -1,6 +1,8 @@ --- title: similarity tags: list,beginner +firstSeen: 2019-08-20T16:12:11+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns a list of elements that exist in both lists. diff --git a/snippets/slugify.md b/snippets/slugify.md index b807564e9..97de6c7db 100644 --- a/snippets/slugify.md +++ b/snippets/slugify.md @@ -1,24 +1,26 @@ ---- -title: slugify -tags: string,regexp,intermediate ---- - -Converts a string to a URL-friendly slug. - -- Use `str.lower()` and `str.strip()` to normalize the input string. -- Use `re.sub()` to to replace spaces, dashes and underscores with `-` and remove special characters. - -```py -import re - -def slugify(s): - s = s.lower().strip() - s = re.sub(r'[^\w\s-]', '', s) - s = re.sub(r'[\s_-]+', '-', s) - s = re.sub(r'^-+|-+$', '', s) - return s -``` - -```py -slugify('Hello World!') # 'hello-world' -``` +--- +title: slugify +tags: string,regexp,intermediate +firstSeen: 2020-10-05T21:57:34+03:00 +lastUpdated: 2020-10-25T12:43:20+02:00 +--- + +Converts a string to a URL-friendly slug. + +- Use `str.lower()` and `str.strip()` to normalize the input string. +- Use `re.sub()` to to replace spaces, dashes and underscores with `-` and remove special characters. + +```py +import re + +def slugify(s): + s = s.lower().strip() + s = re.sub(r'[^\w\s-]', '', s) + s = re.sub(r'[\s_-]+', '-', s) + s = re.sub(r'^-+|-+$', '', s) + return s +``` + +```py +slugify('Hello World!') # 'hello-world' +``` diff --git a/snippets/snake.md b/snippets/snake.md index 5a19b3152..56ac8e45f 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -1,6 +1,8 @@ --- title: snake tags: string,regexp,intermediate +firstSeen: 2019-08-21T08:59:54+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Converts a string to snake case. diff --git a/snippets/some.md b/snippets/some.md index 283cef604..cb06e3645 100644 --- a/snippets/some.md +++ b/snippets/some.md @@ -1,6 +1,8 @@ --- title: some tags: list,intermediate +firstSeen: 2019-08-20T11:42:30+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Checks if the provided function returns `True` for at least one element in the list. diff --git a/snippets/sort_by_indexes.md b/snippets/sort_by_indexes.md index e227e096e..5c34f9cd2 100644 --- a/snippets/sort_by_indexes.md +++ b/snippets/sort_by_indexes.md @@ -1,24 +1,26 @@ ---- -title: sort_by_indexes -tags: list,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 the `reverse` parameter in `sorted()` to sort the dictionary in reverse order, based on the third argument. - -```py -def sort_by_indexes(lst, indexes, reverse=False): - return [val for (_, val) in sorted(zip(indexes, lst), key=lambda x: \ - x[0], reverse=reverse)] -``` - -```py -a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk'] -b = [3, 2, 6, 4, 1, 5] -sort_by_indexes(a, b) # ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges'] -sort_by_indexes(a, b, True) -# ['oranges', 'milk', 'jam', 'eggs', 'bread', 'apples'] -``` +--- +title: sort_by_indexes +tags: list,intermediate +firstSeen: 2020-09-07T09:58:39+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 +--- + +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 the `reverse` parameter in `sorted()` to sort the dictionary in reverse order, based on the third argument. + +```py +def sort_by_indexes(lst, indexes, reverse=False): + return [val for (_, val) in sorted(zip(indexes, lst), key=lambda x: \ + x[0], reverse=reverse)] +``` + +```py +a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk'] +b = [3, 2, 6, 4, 1, 5] +sort_by_indexes(a, b) # ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges'] +sort_by_indexes(a, b, True) +# ['oranges', 'milk', 'jam', 'eggs', 'bread', 'apples'] +``` diff --git a/snippets/sort_dict_by_key.md b/snippets/sort_dict_by_key.md index b5d5b7611..d3371f1c6 100644 --- a/snippets/sort_dict_by_key.md +++ b/snippets/sort_dict_by_key.md @@ -1,6 +1,8 @@ --- title: sort_dict_by_key tags: dictionary,intermediate +firstSeen: 2020-10-16T21:24:33+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Sorts the given dictionary by key. diff --git a/snippets/sort_dict_by_value.md b/snippets/sort_dict_by_value.md index 9bcd0d6f5..1bc807b81 100644 --- a/snippets/sort_dict_by_value.md +++ b/snippets/sort_dict_by_value.md @@ -1,6 +1,8 @@ --- title: sort_dict_by_value tags: dictionary,intermediate +firstSeen: 2020-10-16T21:25:19+03:00 +lastUpdated: 2021-01-08T00:56:50+02:00 --- Sorts the given dictionary by value. diff --git a/snippets/split_lines.md b/snippets/split_lines.md index e447c7b1a..e4e2adffc 100644 --- a/snippets/split_lines.md +++ b/snippets/split_lines.md @@ -1,6 +1,8 @@ --- title: split_lines tags: string,beginner +firstSeen: 2019-08-20T16:15:15+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Splits a multiline string into a list of lines. diff --git a/snippets/spread.md b/snippets/spread.md index 703091b6e..8a4ea0950 100644 --- a/snippets/spread.md +++ b/snippets/spread.md @@ -1,6 +1,8 @@ --- title: spread tags: list,intermediate +firstSeen: 2018-01-08T22:38:05+02:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Flattens a list, by spreading its elements into a new list. diff --git a/snippets/sum_by.md b/snippets/sum_by.md index 3cd5ae8f0..8de6aeeae 100644 --- a/snippets/sum_by.md +++ b/snippets/sum_by.md @@ -1,6 +1,8 @@ --- title: sum_by tags: math,list,beginner +firstSeen: 2019-08-21T08:30:04+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Calculates the sum of a list, after mapping each element to a value using the provided function. diff --git a/snippets/sum_of_powers.md b/snippets/sum_of_powers.md index 1e85bb7d1..a94efdcf9 100644 --- a/snippets/sum_of_powers.md +++ b/snippets/sum_of_powers.md @@ -1,6 +1,8 @@ --- title: sum_of_powers tags: math,intermediate +firstSeen: 2020-10-04T14:21:41+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns the sum of the powers of all the numbers from `start` to `end` (both inclusive). diff --git a/snippets/symmetric_difference.md b/snippets/symmetric_difference.md index d1d24ebd0..1c11740e8 100644 --- a/snippets/symmetric_difference.md +++ b/snippets/symmetric_difference.md @@ -1,6 +1,8 @@ --- title: symmetric_difference tags: list,intermediate +firstSeen: 2019-08-21T08:37:04+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns the symmetric difference between two iterables, without filtering out duplicate values. diff --git a/snippets/symmetric_difference_by.md b/snippets/symmetric_difference_by.md index ee51c2a3a..2d71672e5 100644 --- a/snippets/symmetric_difference_by.md +++ b/snippets/symmetric_difference_by.md @@ -1,6 +1,8 @@ --- title: symmetric_difference_by tags: list,intermediate +firstSeen: 2019-08-21T08:37:04+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns the symmetric difference between two lists, after applying the provided function to each list element of both. diff --git a/snippets/tail.md b/snippets/tail.md index 4f46c7394..f13622fef 100644 --- a/snippets/tail.md +++ b/snippets/tail.md @@ -1,6 +1,8 @@ --- title: tail tags: list,beginner +firstSeen: 2019-08-20T14:08:52+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns all elements in a list except for the first one. diff --git a/snippets/take.md b/snippets/take.md index c1ae195e8..d3837140c 100644 --- a/snippets/take.md +++ b/snippets/take.md @@ -1,18 +1,20 @@ ---- -title: take -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. - -```py -def take(itr, n = 1): - return itr[:n] -``` - -```py -take([1, 2, 3], 5) # [1, 2, 3] -take([1, 2, 3], 0) # [] -``` +--- +title: take +tags: list,beginner +firstSeen: 2020-03-16T19:52:44+02:00 +lastUpdated: 2020-09-15T16:13:06+03:00 +--- + +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. + +```py +def take(itr, n = 1): + return itr[:n] +``` + +```py +take([1, 2, 3], 5) # [1, 2, 3] +take([1, 2, 3], 0) # [] +``` diff --git a/snippets/take_right.md b/snippets/take_right.md index adb0801b3..00798e30f 100644 --- a/snippets/take_right.md +++ b/snippets/take_right.md @@ -1,18 +1,20 @@ ---- -title: take_right -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. - -```py -def take_right(itr, n = 1): - return itr[-n:] -``` - -```py -take_right([1, 2, 3], 2) # [2, 3] -take_right([1, 2, 3]) # [3] -``` +--- +title: take_right +tags: list,beginner +firstSeen: 2020-03-16T19:52:44+02:00 +lastUpdated: 2020-09-15T16:13:06+03:00 +--- + +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. + +```py +def take_right(itr, n = 1): + return itr[-n:] +``` + +```py +take_right([1, 2, 3], 2) # [2, 3] +take_right([1, 2, 3]) # [3] +``` diff --git a/snippets/to_binary.md b/snippets/to_binary.md index d289bd064..c9572d7f5 100644 --- a/snippets/to_binary.md +++ b/snippets/to_binary.md @@ -1,6 +1,8 @@ --- title: to_binary tags: math,beginner +firstSeen: 2020-10-07T19:46:01+03:00 +lastUpdated: 2020-10-07T19:46:01+03:00 --- Returns the binary representation of the given number. diff --git a/snippets/to_dictionary.md b/snippets/to_dictionary.md index 2da19bed7..7507f3bdb 100644 --- a/snippets/to_dictionary.md +++ b/snippets/to_dictionary.md @@ -1,6 +1,8 @@ --- title: to_dictionary tags: list,dictionary,intermediate +firstSeen: 2020-04-13T19:30:29+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- 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. diff --git a/snippets/to_hex.md b/snippets/to_hex.md index d516e563e..1dfbe2124 100644 --- a/snippets/to_hex.md +++ b/snippets/to_hex.md @@ -1,6 +1,8 @@ --- title: to_hex tags: math,beginner +firstSeen: 2020-10-09T09:45:47+03:00 +lastUpdated: 2020-10-09T09:45:47+03:00 --- Returns the hexadecimal representation of the given number. diff --git a/snippets/to_iso_date.md b/snippets/to_iso_date.md index af6f7ac9e..eeb83b3bd 100644 --- a/snippets/to_iso_date.md +++ b/snippets/to_iso_date.md @@ -1,6 +1,8 @@ --- title: to_iso_date tags: date,intermediate +firstSeen: 2020-10-28T16:20:50+02:00 +lastUpdated: 2021-01-07T23:30:28+02:00 --- Converts a date to its ISO-8601 representation. diff --git a/snippets/to_roman_numeral.md b/snippets/to_roman_numeral.md index 5644daf3b..5791b89d2 100644 --- a/snippets/to_roman_numeral.md +++ b/snippets/to_roman_numeral.md @@ -1,6 +1,8 @@ --- title: to_roman_numeral tags: math,string,intermediate +firstSeen: 2020-10-07T00:04:09+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Converts an integer to its roman numeral representation. diff --git a/snippets/transpose.md b/snippets/transpose.md index d020bc382..e2cd0cabd 100644 --- a/snippets/transpose.md +++ b/snippets/transpose.md @@ -1,6 +1,8 @@ --- title: transpose tags: list,intermediate +firstSeen: 2019-10-02T07:03:20+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Transposes a two-dimensional list. diff --git a/snippets/unfold.md b/snippets/unfold.md index 7489d1b2b..d1dfc3c6e 100644 --- a/snippets/unfold.md +++ b/snippets/unfold.md @@ -1,6 +1,8 @@ --- title: unfold tags: function,list,advanced +firstSeen: 2020-01-02T20:17:51+02:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Builds a list, using an iterator function and an initial seed value. diff --git a/snippets/union.md b/snippets/union.md index 57bd56567..05d0d9748 100644 --- a/snippets/union.md +++ b/snippets/union.md @@ -1,6 +1,8 @@ --- title: union tags: list,beginner +firstSeen: 2019-08-21T09:10:39+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns every element that exists in any of the two lists once. diff --git a/snippets/union_by.md b/snippets/union_by.md index b0b98b464..28c635ec4 100644 --- a/snippets/union_by.md +++ b/snippets/union_by.md @@ -1,6 +1,8 @@ --- title: union_by tags: list,intermediate +firstSeen: 2019-08-21T09:10:39+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns every element that exists in any of the two lists once, after applying the provided function to each element of both. diff --git a/snippets/unique_elements.md b/snippets/unique_elements.md index fd21797de..6f643e850 100644 --- a/snippets/unique_elements.md +++ b/snippets/unique_elements.md @@ -1,6 +1,8 @@ --- title: unique_elements tags: list,beginner +firstSeen: 2018-10-09T20:01:19+03:00 +lastUpdated: 2020-09-15T16:13:06+03:00 --- Returns the unique elements in a given list. diff --git a/snippets/values_only.md b/snippets/values_only.md index fa74e6a7f..b3ac16f2b 100644 --- a/snippets/values_only.md +++ b/snippets/values_only.md @@ -1,6 +1,8 @@ --- title: values_only tags: dictionary,list,beginner +firstSeen: 2018-04-01T23:56:31+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Returns a flat list of all the values in a flat dictionary. diff --git a/snippets/weighted_average.md b/snippets/weighted_average.md index 8424ef52a..164d28d93 100644 --- a/snippets/weighted_average.md +++ b/snippets/weighted_average.md @@ -1,6 +1,8 @@ --- title: weighted_average tags: math,list,intermediate +firstSeen: 2020-10-09T07:00:33+03:00 +lastUpdated: 2020-12-24T15:00:53+02:00 --- Returns the weighted average of two or more numbers. diff --git a/snippets/when.md b/snippets/when.md index 5d19dd253..93869d6b0 100644 --- a/snippets/when.md +++ b/snippets/when.md @@ -1,6 +1,8 @@ --- title: when tags: function,intermediate +firstSeen: 2020-01-02T20:25:45+02:00 +lastUpdated: 2020-11-09T23:56:11+02:00 --- Tests a value, `x`, against a testing function, conditionally applying a function. diff --git a/snippets/words.md b/snippets/words.md index e9182de16..4986328e8 100644 --- a/snippets/words.md +++ b/snippets/words.md @@ -1,6 +1,8 @@ --- title: words tags: string,regexp,beginner +firstSeen: 2020-10-04T00:35:00+03:00 +lastUpdated: 2020-11-02T19:28:35+02:00 --- Converts a given string into a list of words.