<jupyter_start><jupyter_text>Use comprehensions and reduce to answer the question below<jupyter_code>msg="""is it possible to star emails from this message for example
if there is an email such as <EMAIL> replace it with stars,
another one is <EMAIL>"""
' '.join(
    [
        word if '@' not in word else '*' * len(word)
        for word in msg.split()
    ]
)<jupyter_output><empty_output><jupyter_text>What is the longest word in msg [answer is "<EMAIL>"]<jupyter_code>max_length = reduce( lambda x, y: x if x > y else y , 
    [len(word) for word in words]
)
# using filtering
max_length = max([len(word) for word in msg.split()])
[word for word in msg.split() if len(word) == max_length]
# using reduce
def longer(word1, word2):
    longer_word = word1 if len(word1) > len(word2) else word2
    return longer_word

# example
longer("java", "python")
from functools import reduce

reduce(longer, msg.split())
# or using lambda

reduce(lambda w1, w2: w1 if len(w1) > len(w2) else w2, msg.split())<jupyter_output><empty_output><jupyter_text>What is the longest word in msg that is not an email [answer is "possible"]<jupyter_code># using filtering
max_length = max([len(word) for word in msg.split() if '@' not in word])
[word for word in msg.split() if len(word) == max_length]
reduce(longer,
       [word for word in msg.split() if '@' not in word]
      )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12293314162473042, 'fraction_numerical': 0.008626887131560028, 'mean_word_length': 4.480314960629921, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '298773', 'license': 'MIT', 'n_tokens_mistral': 480, 'n_tokens_neox': 473, 'n_words': 169, 'path': '10-workout-solution_comprehensions.ipynb', 'repo_name': 'hanisaf/advanced-data-management-and-analytics', 'size': '1430'}