Hi all, I am very new to python and for my class we have to be able to get the answer to this expression without using python, so the answer is there but we would not be able to see that during the test. I was wondering if someone could explain to me how you get the answer of {'o': 3, 'k': 2, 'e': 7, 'm': 2, 'n': 1, 'a': 2, 'd': 1} from the expression
{ c:S.count© for c in "".join([ w[1:] for w in S.split() if "e" not in w[-3:-1] and "o" in w[:4] ]) } with S="coffee coke tea lemonade milk sprite". Ive been looking at it for the past hour and cannot figure out why the "i" and "L" are not counted but the "m" and the "k" are counted in milk and I dont really understand why "o" and "e" are always counted even if the word does not meet the if conditions. Thanks
S = "coffee coke tea lemonade milk sprite"
>>> { c:S.count© for c in "".join([ w[1:] for w in S.split() if "e" not in w[-3:-1] and "o" in w[:4] ]) }
{'o': 3, 'k': 2, 'e': 7, 'm': 2, 'n': 1, 'a': 2, 'd': 1}
{ c:S.count© for c in "".join([ w[1:] for w in S.split() if "e" not in w[-3:-1] and "o" in w[:4] ]) } with S="coffee coke tea lemonade milk sprite". Ive been looking at it for the past hour and cannot figure out why the "i" and "L" are not counted but the "m" and the "k" are counted in milk and I dont really understand why "o" and "e" are always counted even if the word does not meet the if conditions. Thanks
S = "coffee coke tea lemonade milk sprite"
>>> { c:S.count© for c in "".join([ w[1:] for w in S.split() if "e" not in w[-3:-1] and "o" in w[:4] ]) }
{'o': 3, 'k': 2, 'e': 7, 'm': 2, 'n': 1, 'a': 2, 'd': 1}

