added README.md for List-Comprehension exercise

This commit is contained in:
2024-02-11 00:20:19 +01:00
parent 1121c6a171
commit 14cd9fe8b0

View File

@ -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]
```
---