Colab

num1  = 15
num2 = num1

help([].extend)

Help on built-in function extend:

extend(...) method of builtins.list instance
    L.extend(iterable) -> None -- extend list by appending elements from the iterable

x = [4,5,6]

x.insert(0, [1,2,3])

len(x)

4
x

[[1, 2, 3], 4, 5, 6]
x = [4,5,6]
x = [1,2,3] + x

x

[1, 2, 3, 4, 5, 6]
["one", "two", "three"].remove("one")

x = ["one", "two", "three"]

x.remove("one")

x

['two', 'three']
stuff_to_do = [
    "buy milk",
    "cancel subscription",
    "go to work",
    "gym"
]

def do_stuff(work):
    print(work)

while stuff_to_do:
    work = stuff_to_do.pop()
    do_stuff(work)
    

gym
go to work
cancel subscription
buy milk
stuff_to_do = [
    "work",
    "live",
    "breath",
    "buy milk",
    "cancel subscription",
    "go to work",
    "gym",
    "try harder",
    "catch zzs"
]

stuff_to_do.pop(stuff_to_do.index('gym'))

'gym'
stuff_to_do

['buy milk', 'cancel subscription', 'go to work']
for i in range(len(stuff_to_do)):
    for j in range(i, len(stuff_to_do)):
        if stuff_to_do[i] > stuff_to_do[j]:
            stuff_to_do[i], stuff_to_do[j] = stuff_to_do[j], stuff_to_do[i]

stuff_to_do

['breath',
 'buy milk',
 'cancel subscription',
 'catch zzs',
 'go to work',
 'gym',
 'live',
 'try harder',
 'work']
min = stuff_to_do[0]
for i in range(len(stuff_to_do[1:])):
    if min >  stuff_to_do[i]:
        min = stuff_to_do[i]
    
print(min)

breath
for i in range(len(stuff_to_do)):
    
    min_j = i
    min = stuff_to_do[min_j]
    
    for j in range(i+1, len(stuff_to_do)):
        if min >  stuff_to_do[j]:
            min_j = j
            min = stuff_to_do[min_j]
    
    stuff_to_do[i], stuff_to_do[min_j] = stuff_to_do[min_j], stuff_to_do[i]
    

print(stuff_to_do)

['breath', 'buy milk', 'cancel subscription', 'catch zzs', 'go to work', 'gym', 'live', 'try harder', 'work']
sorted(stuff_to_do, reverse=True)

['work',
 'try harder',
 'live',
 'gym',
 'go to work',
 'catch zzs',
 'cancel subscription',
 'buy milk',
 'breath']
lists = [
    [2, 2000],
    [1,1,1],
    [100, 75],
    [50, 50, 90],
    [10, 20, 30]
]

sorted(lists, key=len)

[[2], [100], [50, 50], [1, 1, 1]]
sorted(lists, key=max)

[[1, 1, 1], [2], [50, 50], [100]]
sorted(lists, key=min)

[[1, 1, 1], [2, 2000], [10, 20, 30], [50, 50, 90], [100, 75]]
sorted(lists, key=max)

[[1, 1, 1], [10, 20, 30], [50, 50, 90], [100, 75], [2, 2000]]
import math

help(math.pow)

Help on built-in function pow in module math:

pow(...)
    pow(x, y)
    
    Return x**y (x to the power of y).

sorted(lists, key=str)

[[1, 1, 1], [10, 20, 30], [100, 75], [2, 2000], [50, 50, 90]]
sorted(lists, key=sum)

[[1, 1, 1], [10, 20, 30], [100, 75], [50, 50, 90], [2, 2000]]
help(sum)

Help on built-in function sum in module builtins:

sum(iterable, start=0, /)
    Return the sum of a 'start' value (default: 0) plus an iterable of numbers
    
    When the iterable is empty, return the start value.
    This function is intended specifically for use with numeric values and may
    reject non-numeric types.

lists2 = [
    [10, 20, 30],
    [100, -100],
    [15, 75],
    [1000, 500, 200, 50]
]

sorted(lists2, key=min)

[[100, -100], [10, 20, 30], [15, 75], [1000, 500, 200, 50]]
sorted(lists2, key=max)

[[10, 20, 30], [15, 75], [100, -100], [1000, 500, 200, 50]]