Python: Sum the length of the names of a given list of names after removing the names that starts with a lowercase letter
22. Sum Length of Names Lambda
Write a Python program that sums the length of a list of names after removing those that start with lowercase letters. Use the lambda function.
Sample Solution:
Python Code :
# Create a list of strings named 'sample_names' containing various names
sample_names = ['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith']
# Filter the 'sample_names' list using a lambda function to include only names that start with an uppercase letter
# followed by lowercase letters for the rest of the name
sample_names = list(filter(lambda el: el[0].isupper() and el[1:].islower(), sample_names))
# Print a label for the upcoming result
print("Result:")
# Calculate the total length of the concatenated string formed by joining all the filtered names together
print(len(''.join(sample_names)))
Sample Output:
Result: 16
For more Practice: Solve these Related Problems:
- Write a Python program to sum the lengths of names that contain at least one uppercase letter using lambda.
- Write a Python program to sum the lengths of names that do not contain any numeric digits using lambda.
- Write a Python program to sum the lengths of names that end with a vowel using lambda.
- Write a Python program to sum the lengths of names that have more than 5 characters using lambda.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program that multiply each number of given list with a given number using lambda function. Print the result.
Next: Write a Python program to calculate the sum of the positive and negative numbers of a given list of numbers using lambda function.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.