From 14cd9fe8b0e6f05b527397f51fa254e350adccc9 Mon Sep 17 00:00:00 2001 From: Daniel Mironov Date: Sun, 11 Feb 2024 00:20:19 +0100 Subject: [PATCH] added README.md for List-Comprehension exercise --- list_comprehensions/README.md | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/list_comprehensions/README.md b/list_comprehensions/README.md index 59e3bce..2ed4ed9 100644 --- a/list_comprehensions/README.md +++ b/list_comprehensions/README.md @@ -1 +1,56 @@ # List Comprehensions + +## Aufgabe 1 - Divisible by 7 +Schreibe eine List-Comprehension welche eine Liste an Zahlen bis `n` zurückgibt, welche dividierbar durch 7 sind. + +### Examples +```python +assert divisible_by_7(0) == [] +assert divisible_by_7(10) == [7] +assert divisible_by_7(43) == [7, 14, 28, 35, 42] +``` + +--- +## Aufgabe 2 - Contains 3 +Schreibe eine List-Comprehension welche eine Liste an Zahlen bis `n` zurückgibt, welche eine `3` enthalten. +### Examples +```python +assert contains_3(10) == [3] +assert contains_3(24) == [3, 13, 23] +``` +--- +## Aufgabe 3 - Count Spaces +Schreibe eine Funktion, welche die Whitespaces (`' '`) in einem String zählt. Verwende hierzu List-Comprehensions. +### Examples +```python +assert count_spaces('') == 0 +assert count_spaces(' ') == 1 +assert count_spaces('hello, world ') == 2 +``` + +--- +## Aufgabe 4 - Remove Vowels +Schreibe eine Funktion, welche alle Vokale (`'AEIOUaeiou'`) aus einem String entfernt. Verwendet hierfür List-Comprehension +### Examples +```python +assert remove_vowels('') == '' +assert remove_vowels(' ') == ' ' +assert remove_vowels('hello, world') == 'hll, wrld' +``` + +--- +## Aufgabe 5 - Wortlängen +Schreibe eine Dictionary comprehension, welche ein Dictionary zurückgibt, wo die länge aller Wörter zu finden ist. +### Example +```python +assert word_length('this is a string') == {'this': 4, 'is': 2, 'a': 1, 'string': 6} +``` + +--- +## Aufgabe 6 - Primzahlen generieren (schwer) +Schreibe eine Funktion, welche ein Liste an allen Primzahlen bis `n` zurückgibt. Verwende hierzu List-Comprehensions +### Examples +```python +assert prime_numbers(100) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] +``` +---