words = ["anyone", "cancel", "declArE", "perlmonks", "pal"] print(*((word,word.upper().count('E')) for word in words if 'A' in word.upper()))