GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Sum the length of the names of a given list of names after removing the names that starts with a lowercase letter - w3resource

Python: Sum the length of the names of a given list of names after removing the names that starts with a lowercase letter

Last update on July 12 2025 13:05:10 (UTC/GMT +8 hours)


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.

Go to:

  • Python Lambda Exercises Home ↩
  • Python Exercises Home ↩

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.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.