Python: Find the values of length six in a given list using Lambda
Python Lambda: Exercise-14 with Solution
Write a Python program to find the values of length six in a given list using Lambda.
Sample Solution:
Python Code :
weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
days = filter(lambda day: day if len(day)==6 else '', weekdays)
for d in days:
print(d)
Sample Output:
Monday Friday Sunday
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to count the even, odd numbers in a given array of integers using Lambda.
Next: Write a Python program to add two given lists using map and lambda.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Returns all the elements of a list except the last one
Example:
def tips_initial(lst): return lst[0:-1] print(tips_initial([1, 2, 3, 4]))
Output:
[1, 2, 3]
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework