diff --git a/snippets/all_unique.md b/snippets/all_unique.md index 097b22310..9deab7e33 100644 --- a/snippets/all_unique.md +++ b/snippets/all_unique.md @@ -9,7 +9,7 @@ Use `set()` on the given list to remove duplicates, compare its length with the ```py def all_unique(lst): - return len(lst) == len(set(lst)) + return len(lst) == len(set(lst)) ``` ```py diff --git a/snippets/average.md b/snippets/average.md index 0fda74d5c..0a663c3bc 100644 --- a/snippets/average.md +++ b/snippets/average.md @@ -1,16 +1,15 @@ --- title: average -tags: math +tags: math,list,beginner --- -:information_source: Already implemented via `statistics.mean`. `statistics.mean` takes an array as an argument whereas this function takes variadic arguments. Returns the average of two or more numbers. -Takes the sum of all the `args` and divides it by `len(args)`. The second argument `0.0` in sum is to handle floating point division in `python3`. +Use `sum()` to sum all of the `args` provided, divide by `len(args)`. ```py def average(*args): - return sum(args, 0.0) / len(args) + return sum(args, 0.0) / len(args) ``` ```py diff --git a/snippets/bubble_sort.md b/snippets/bubble_sort.md deleted file mode 100644 index 002a3a3d7..000000000 --- a/snippets/bubble_sort.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: bubble_sort -tags: list ---- - -Bubble_sort uses the technique of comparing and swapping - -```py -def bubble_sort(lst): - for passnum in range(len(lst) - 1, 0, -1): - for i in range(passnum): - if lst[i] > lst[i + 1]: - lst[i], lst[i + 1] = lst[i + 1], lst[i] - -``` - -```py -lst = [54,26,93,17,77,31,44,55,20] -bubble_sort(lst) -print("sorted %s" %lst) # [17,20,26,31,44,54,55,77,91] -``` diff --git a/snippets/byte_size.md b/snippets/byte_size.md index 7cdc81c0f..0a191260d 100644 --- a/snippets/byte_size.md +++ b/snippets/byte_size.md @@ -1,14 +1,15 @@ --- title: byte_size -tags: string +tags: string, beginner --- + Returns the length of a string in bytes. -`utf-8` encodes a given string, then `len` finds the length of the encoded string. +Use `string.encode('utf-8')` to encode the given string and return its length. ```py def byte_size(string): - return(len(string.encode('utf-8'))) + return len(string.encode('utf-8')) ``` ```py