File tree Expand file tree Collapse file tree 3 files changed +4
-7
lines changed
exercises/practice/pangram
.articles/performance/code Expand file tree Collapse file tree 3 files changed +4
-7
lines changed Original file line number Diff line number Diff line change 22
33``` python
44def 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
Original file line number Diff line number Diff line change 11def 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
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ def is_pangram(sentence):
2828val = timeit .timeit ("""is_pangram("Victor jagt zwölf_(12) Boxkämpfer quer über den großen Sylter Deich.")""" ,
2929 """
3030def 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
You can’t perform that action at this time.
0 commit comments