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]
|
numbers = [1, 2, 3, 4, 5]
|
||||||
|
result = list(map(lambda x: x * 2, [1, 2, 3, 4, 5]))
|
||||||
# Verdopplung aller Zahlen mittels map
|
print(result)
|
||||||
result = list(map(lambda x: x * 2, numbers))
|
|
||||||
|
|
||||||
print("Ergebnis:", result)
|
|
||||||
#assert result == [2, 4, 6, 8, 10]
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
words = ["huge", "great", "tremendous", "fake news"]
|
words = ["huge", "great", "tremendous", "fake news"]
|
||||||
|
|
||||||
# Strings in Großbuchstaben umwandeln und "!" anhängen
|
# Strings in Großbuchstaben umwandeln und "!" anhängen
|
||||||
result = list(map(lambda word: word.upper() + "!", words))
|
result = list(map(lambda word: word.upper() + "!", words))
|
||||||
|
|
||||||
print("Ergebnis:", result)
|
print("Ergebnis:", result)
|
||||||
#assert result == ["HUGE!", "GREAT!", "TREMENDOUS!", "FAKE NEWS!"]
|
#assert result == ["HUGE!", "GREAT!", "TREMENDOUS!", "FAKE NEWS!"]
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
|
|
||||||
# Nur gerade Zahlen (x % 2 == 0) herausfiltern
|
# Nur gerade Zahlen (x % 2 == 0) herausfiltern
|
||||||
result = list(filter(lambda x: x % 2 == 0, numbers))
|
result = list(filter(lambda x: x % 2 == 0, numbers))
|
||||||
|
|
||||||
print("Ergebnis:", result)
|
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
|
# Einzeiler kombiniert filter, map und sum
|
||||||
total_length = sum(map(len, filter(lambda w: w.lower().startswith('k'), words)))
|
total_length = sum(map(len, filter(lambda w: w.lower().startswith('k'), words)))
|
||||||
|
|
||||||
print("Gesamtlänge aller K-Wörter:", total_length)
|
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