modified
This commit is contained in:
1 parent
d327f5d7e6
commit
8431a9955a
4 files changed
+4
-13
No files matched your search
+2
-6
@@ -1,7 +1,3 @@
|
||||
numbers = [1, 2, 3, 4, 5]
|
||||
|
||||
# Verdopplung aller Zahlen mittels map
|
||||
result = list(map(lambda x: x * 2, numbers))
|
||||
|
||||
print("Ergebnis:", result)
|
||||
#assert result == [2, 4, 6, 8, 10]
|
||||
result = list(map(lambda x: x * 2, [1, 2, 3, 4, 5]))
|
||||
print(result)
|
||||
@@ -1,7 +1,5 @@
|
||||
words = ["huge", "great", "tremendous", "fake news"]
|
||||
|
||||
# Strings in Großbuchstaben umwandeln und "!" anhängen
|
||||
result = list(map(lambda word: word.upper() + "!", words))
|
||||
|
||||
print("Ergebnis:", result)
|
||||
#assert result == ["HUGE!", "GREAT!", "TREMENDOUS!", "FAKE NEWS!"]
|
||||
@@ -1,7 +1,4 @@
|
||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
|
||||
# Nur gerade Zahlen (x % 2 == 0) herausfiltern
|
||||
result = list(filter(lambda x: x % 2 == 0, numbers))
|
||||
|
||||
print("Ergebnis:", result)
|
||||
assert result == [2, 4, 6, 8, 10]
|
||||
+2
-2
@@ -2,6 +2,6 @@ words = ["Kuchen", "Katze", "Apfel", "Kaffee", "Baum", "Kino"]
|
||||
|
||||
# Einzeiler kombiniert filter, map und sum
|
||||
total_length = sum(map(len, filter(lambda w: w.lower().startswith('k'), words)))
|
||||
|
||||
print("Gesamtlänge aller K-Wörter:", total_length)
|
||||
assert total_length == 6 + 5 + 6 + 4 # Kuchen (6) + Katze (5) + Kaffee (6) + Kino (4) = 21
|
||||
|
||||
#assert total_length == 6 + 5 + 6 + 4 # Kuchen (6) + Katze (5) + Kaffee (6) + Kino (4) = 21
|
||||
Reference in new issue
Block a user