pr3-skriptspr-gruppef-sl1/s1_a53_6.py

53 lines
1.2 KiB
Python

#5.3
list1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print("start list: ", list1)
list1.insert(0, list1.pop())
list1.insert(0, list1.pop())
list1.insert(0, list1.pop())
print("new list: ", list1)
print()
print()
#---------------------------------------------------------------------------------------------------------
#5.4
#a
word = "DONAUDAMPFSCHIFFAHRTSGESELLSCHAFTSSTEWARDESS"
letters = list(word)
print(letters)
print("length:", len(letters))
#b
letters_once = []
for element in letters:
if element not in letters_once:
letters_once.append(element)
print(letters_once)
print("new length:", len(letters_once))
print()
print()
#---------------------------------------------------------------------------------------------------------
#5.5
list2 = [[1, 2, 3], [2, 1, 3], [4, 0, 1]]
print("List2 unsorted:", list2)
list2.sort(key = lambda list2: list2[1])
print("List2 sorted by 2nd value:", list2)
print()
print()
#---------------------------------------------------------------------------------------------------------
#5.6
dict = { "Hund" : "wuff", "Katze" : "miau", "Kuh" : "muuh" }
def function2(d, a):
print(a, ":", d[a])
function2(dict, "Hund")
function2(dict, "Katze")
function2(dict, "Kuh")