s = 'abc12321cba'
print(s.replace('a', ''))
bc12321cb
numbers.sort(reverse = True)# reverse is set to True
sorted(set(L))
sorted(L)# sorterer duh
set()# fjerner dupes
xxx = {}#creates empty dictionary
set()#
s = 'hello world'
print(s.upper()) # HELLO WORLD
print(s.lower()) # hello world
print(s.capitalize()) # Hello world
print(s[::-1]) # Reverse the string: dlrow olleh
print(s.count('l')) # Counts occurrences of 'l': 3
print(s.find('world')) # Finds index of 'world': 6
print(s.strip()) # Removes leading/trailing spaces
L = [3, 1, 2, 3, 4] #list
L.append(5) # Adds 5 to the end: [3, 1, 2, 3, 4, 5]
L.remove(3) # Removes the first occurrence of 3: [1, 2, 3, 4, 5]
L.pop() # Removes and returns the last element: [1, 2, 3, 4]
L.insert(1, 10) # Inserts 10 at index 1: [1, 10, 2, 3, 4]
L.extend([6, 7]) # Extends the list: [1, 10, 2, 3, 4, 6, 7]
print(L[::-1]) # Reverses the list: [7, 6, 4, 3, 2, 10, 1]
print(max(L)) # Finds the largest number: 10
print(min(L)) # Finds the smallest number: 1
s1 = {1, 2, 3} #set
s2 = {3, 4, 5}
print(s1 | s2) # Union: {1, 2, 3, 4, 5}
print(s1 & s2) # Intersection: {3}
print(s1 - s2) # Difference: {1, 2}
print(s1 ^ s2) # Symmetric Difference: {1, 2, 4, 5}
print(len(s1)) # Length of the set: 3
s1.add(6) # Adds 6: {1, 2, 3, 6}
s1.remove(1) # Removes 1: {2, 3, 6}
d = {'a': 1, 'b': 2, 'c': 3} #dict
print(d.keys()) # dict_keys(['a', 'b', 'c'])
print(d.values()) # dict_values([1, 2, 3])
print(d.items()) # dict_items([('a', 1), ('b', 2), ('c', 3)])
d['d'] = 4 # Adds key 'd': {'a': 1, 'b': 2, 'c': 3, 'd': 4}
del d['a'] # Deletes key 'a': {'b': 2, 'c': 3, 'd': 4}
print(d.get('b')) # Gets value for 'b': 2
print(d.pop('b')) # Removes and returns 'b': {'c': 3, 'd': 4}
d.clear() # Empties the dictionary
nums = [1, 2, 3, 4, 5]
print(sum(nums)) # Sum of all elements: 15
print(len(nums)) # Length of the list: 5
print(max(nums)) # Largest element: 5
print(min(nums)) # Smallest element: 1
print(list(range(5))) # Creates a list: [0, 1, 2, 3, 4]
print(enumerate(nums)) # Pairs index with value
for i, n in enumerate(nums):
print(i, n) # Prints index and value
def my_function(shopping_cart, prices):
total_cost = 0 # Initialize the total cost to 0
if not shopping_cart: # Check if the shopping cart is empty
return 0 # If empty, return 0
for item, quantity in shopping_cart: # Loop through each item and its quantity in the cart
if item in prices: # Check if the item exists in the price list
total_cost += quantity * prices[item] # Add the cost (quantity * price) to the total cost
return total_cost