You need to extract words from a list of sentences and filter them based on their length. Specifically, you want to create a list of words that are shorter than or equal to a given length limit, which the user will provide as input.To solve this problem:
1. Data Preparation:
- You start with a list of lists, where each sublist contains words from different sentences.
2. Input Handling:
- You prompt the user to enter a length limit for filtering the words.
3. Flattening the List:
- You flatten the nested list structure into a single list that contains all the words from all the sentences. This is done to make it easier to process each word individually.
4. Filtering Words:
- You iterate through the flattened list of words and check the length of each word.
- If the length of a word is less than or equal to the specified limit, you add that word to a new list.
5. Output:
- Finally, you print the list of filtered words.
The approach ensures that only words meeting the length criterion are included in the final list, making it straightforward to analyze or process these filtered words further.