Skip to the content.
3.1 and 3.4 3.2 3.3 and 3.5 3.8 3.10

3.10 Hacks

hacks

DevOps

Popcorn Hacks

Popcorn Hack 1

aList = [1, 2, 3, 'apple', 'samsung']
print('Initial list:', aList)

aList.append('huawei')
print('Appended list:', aList)
Initial list: [1, 2, 3, 'apple', 'samsung']
Appended list: [1, 2, 3, 'apple', 'samsung', 'huawei']

Popcorn Hack 2

aList = ['apple', 'samsung', 'huawei', 'oneplus', 'pixel']
print('Initial list:', aList)

aList.insert(1, 'htc')
print('htc inserted after samsung:', aList)

aList.remove('huawei')
print('Huawei gone list:', aList)

del aList[0]
print('Index 0 gone list:', aList)
Initial list: ['apple', 'samsung', 'huawei', 'oneplus', 'pixel']
htc inserted after samsung: ['apple', 'htc', 'samsung', 'huawei', 'oneplus', 'pixel']
Huawei gone list: ['apple', 'htc', 'samsung', 'oneplus', 'pixel']
Index 0 gone list: ['htc', 'samsung', 'oneplus', 'pixel']

Popcorn Hack 3

aList = ['apple', 'samsung', 'huawei']
print('Initial list:', aList)
aList[1] = 'pixel'
print('Samsung replaced with pixel list:', aList)
Initial list: ['apple', 'samsung', 'huawei']
Samsung replaced with pixel list: ['apple', 'pixel', 'huawei']

Homework Hack

aList = [12, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1]

even_sum = 0

for score in aList:
   if score % 2 == 0:
       even_sum += score

min_value = min(aList)
max_value = max(aList)

print("Sum of even numbers in the list:", even_sum)
print("Minimum value in the list:", min_value)
print("Maximum value in the list:", max_value)
Sum of even numbers in the list: 42
Minimum value in the list: 1
Maximum value in the list: 12