<jupyter_start><jupyter_text>Python in Action Part 1: Python Fundamentals 35 &mdash; Collection functions> useful Collection functions: sum, max, min, sorted... Python provides a group of useful global functions for collections:+ `sum` &mdash; sums the elements of a collection+ `max` &mdash; returns the maximum element of a collection+ `min` &mdash; return the minimum element of a collection+ `sorted` &mdash; returns a sorted collection from the given one without mutating the original collection+ `reversed` &mdash; returns a reversed collection from the given one without mutating the original collection<jupyter_code>import random

print(sum([1, 2, 3]))
print(max([1, 2, 3]))
print(min([1, 2, 3]))

unsorted_nums = [random.randint(0, 10) for _ in range(0, 10) ]
print(unsorted_nums)
print(sorted(unsorted_nums))
print(unsorted_nums) # original list has not been mutated

nums = [1, 2, 3, 4, 5]
print(list(reversed(nums))) # list is needed to materialize
print(nums) # original list has not been mutated<jupyter_output>6
3
1
[6, 10, 7, 8, 5, 0, 8, 3, 7, 6]
[0, 3, 5, 6, 6, 7, 7, 8, 8, 10]
[6, 10, 7, 8, 5, 0, 8, 3, 7, 6]
[5, 4, 3, 2, 1]
[1, 2, 3, 4, 5]
{'fraction_non_alphanumeric': 0.12953367875647667, 'fraction_numerical': 0.05958549222797927, 'mean_word_length': 5.264864864864865, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '480089', 'license': 'MIT', 'n_tokens_mistral': 472, 'n_tokens_neox': 405, 'n_words': 171, 'path': '01-python-basics/35-collection-functions.ipynb', 'repo_name': 'sergiofgonzalez/python-in-action', 'size': '1158'}