Skip to content

Commit b4259d9

Browse files
committed
feat(practice/pangram): update code snippets in approaches for set with len()
Fixes: Cc: Reviewed-by:
1 parent 1a164c7 commit b4259d9

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

exercises/practice/pangram/.approaches/set-len/content.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
```python
44
def is_pangram(sentence):
5-
return len([ltr for ltr in set(sentence.lower()) if ltr.isalpha()]) \
6-
== 26
7-
5+
return len(set(ltr for ltr in sentence.lower() if ltr.isalpha())) == 26
86
```
97

108
- This approach first makes a [set][set] from the [`lower`][lower]cased characters of the `sentence`.
119
- The characters in the `set`are then iterated in a [list comprehension][list-comprehension].
1210
- The characters are filtered by an `if` [`isalpha()`][isalpha] statement, so that only alphabetic characters make it into the list.
1311
- The function returns whether the [`len()`][len] of the [`list`][list] is `26`.
14-
If the number of unique letters in the `set` is equal to the `26` letters in the alphabet, then the function will return `True`.
12+
If the number of unique letters in the `set` is equal to the `26` letters in the alphabet, then the function will return `True`.
1513

1614
[lower]: https://docs.python.org/3/library/stdtypes.html?#str.lower
1715
[set]: https://docs.python.org/3/library/stdtypes.html?#set
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
def is_pangram(sentence):
2-
return len([ltr for ltr in set(sentence.lower()) if ltr.isalpha()]) \
3-
== 26
2+
return len(set(ltr for ltr in sentence.lower() if ltr.isalpha())) == 26

exercises/practice/pangram/.articles/performance/code/Benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def is_pangram(sentence):
2828
val = timeit.timeit("""is_pangram("Victor jagt zwölf_(12) Boxkämpfer quer über den großen Sylter Deich.")""",
2929
"""
3030
def is_pangram(sentence):
31-
return len([ltr for ltr in set(sentence.lower()) if ltr.isalpha()]) == 26
31+
return len(set(ltr for ltr in sentence.lower() if ltr.isalpha())) == 26
3232
3333
""", number=loops) / loops
3434

0 commit comments

Comments
 (0)