🔍 Daily Python Problem: Hunt for the Longest Word! 💖
Let's do some fun problems today and use some of Python's cool functions! 🐍
Problem: Write the function named find _ long _ word (sentence) that receives the String (that is a sentence) and must return the longest word in that sentence!
• Special Requirements: If there are many words of the same length, restore the first word found enough!
💡 Crucial Tip: The String Split!
The first thing we need to do is to "blow" long sentences into a list of words. We use the .split ("") method to separate the String with spaces. This is the list of words in the loop!
🌟 There are two great ways to show it:
1.Basic Type (Loop Use):
• Start by splitting the String with .split ("") first
• Define the variable max _ length = 0 and long _ word = ""
• Loop in the list of words to check the length of each word and update the max _ length and long _ word.
2.Pythonic (use max with key):
• This is very short and beautiful! We use the max function (iterable, key = function).
• By assigning key = len (len is the length function), Python will find the "word" in the list that makes the len () function the highest value! It also follows that Requirements, if equal, will restore the first word found!
• Don't forget: Check the case where the list is empty if not words: before returning the answer!
Example:
• Input: "Python is a popular programming language."
• Output: "programming"
Let's try to practice writing and know that Python makes String Management a lot easier! Keep going. 🥰






















































































