So, my problem is to understand comparison between lists.
I had a homework to compare if some string has all the letters from the alphabet, so i did this:
import string
def ispangram(str):
letters = ''.join(str.split()).lower()
unique_letters = set(letters)
sorted_list = list(sorted(unique_letters))
str_alphabet = ''.join(sorted_list)
alphabet = string.ascii_lowercase
if str_alphabet == alphabet:
print(True)
else:
print(False)
ispangram("The quick brown fox jumps over the lazy dog")
Ok, i got True, thats fine. But the other way for the answer is:
import string
def ispangram(str):
alphabet = string.ascii_lowercase
alphaset = set(alphabet)
return alphaset <= set(str.lower()):
ispangram("The quick brown fox jumps over the lazy dog")
So this "<=" that i cant understand. It compares letter by letter in the set unique list? Or it just compare the lenght of it? Because without joining i get Space ' ' too.
And how does "<=" compare if only "set(str.lower())" does not sort every letter?
Hope somebody could help me, thanks a lot!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…