assuming words are separated by space,

S="this is my sentense"

"".join(map(lambda x: x[0], S.split(" ")))

returns

'tims'

explanation :

  • split in words using space
  • for each word ("map" function), take first character (x[0])
  • then join the result using void
Answer from Setop on Stack Overflow
🌐
Python.org
discuss.python.org › python help
Sum strings in a list - Python Help - Discussions on Python.org
January 25, 2023 - Dear Python Experts, I started learning Python one month ago and I am not sure if I am doing the right thing to sum values in a list. I have the following list with car models and I would like to sum the total vehicle a…
Discussions

types - Python sum, why not strings? - Stack Overflow
Python has a built in function sum, which is effectively equivalent to: def sum2(iterable, start=0): return start + reduce(operator.add, iterable) for all types of parameters except strings. It works for numbers and lists, for example: More on stackoverflow.com
🌐 stackoverflow.com
i’m trying to print the sum of numbers in a list and can’t seem to figure it out.
(I'm a beginner :|) You are trying to add strings to find a sum This worked- input_string=input("Please enter seven integer numbers: ") List=input_string.split() print(List) #input takes string, but to add we need int/float integer_List=[] for i in List: integer_List.append(int(i))#creating a new list to store integer values print("integers: ",integer_List) integer_List.sort() print(integer_List) #to calculate the sum num_sum=sum(integer_List) #declaring counter variable print("Sum=",num_sum) Output: Please enter seven integer numbers: 3 4 7 5 9 4 6 ['3', '4', '7', '5', '9', '4', '6'] integers: [3, 4, 7, 5, 9, 4, 6] [3, 4, 4, 5, 6, 7, 9] Sum= 38 More on reddit.com
🌐 r/CodingHelp
5
2
March 2, 2021
Can someone explain to me how to add up all the numbers in a list without using sum?
Use a for loop! Iterate over the list and add each number to the final total More on reddit.com
🌐 r/learnpython
39
21
June 27, 2022
Is there a reason lists don't have a .sum() method?
I am gonna presume that it has something to do with the fact that lists can contain any python objects not just integers and floats, sumable objects (objects with add() and radd() special methods). So in many cases [...].sum() would fail if it was called on a list of regular strings or other python objects that can't be summed. And since Zen oF Python states that explicit is better than implicit the current way it is done has much more sense. I guess something along those lines. More on reddit.com
🌐 r/Python
31
4
November 25, 2021
🌐
Bobby Hadz
bobbyhadz.com › blog › python-sum-with-strings
How to sum a List of Strings in Python | bobbyhadz
Use a generator expression to iterate over the string. On each iteration, convert each character to an integer if it is a digit. Use the sum() function to get the sum of the digits.
🌐
GeeksforGeeks
geeksforgeeks.org › python › sum-of-list-with-string-types-in-python
Sum of list (with string types) in Python - GeeksforGeeks
July 11, 2025 - Time Complexity: O(n), where n is the length of the list. Auxiliary Space: O(1) An alternative approach to sum a list with string elements in Python is to use the try and except statements to handle the case when a string element cannot be converted to an integer.
🌐
Medium
medium.com › @glasshost › how-to-sum-a-list-of-strings-in-python-f3b06d0bbc65
How to sum a List of Strings in Python - Glasshost - Medium
April 23, 2023 - Convert the list of strings to a list of integers using a loop and the `int()` function. int_list = [] for item in my_list: int_list.append(int(item)) Use the `sum()` function to add up the integers.
🌐
TutorialsPoint
tutorialspoint.com › article › get-the-summation-of-numbers-in-a-string-list-using-python
Get the summation of numbers in a string list using Python
July 17, 2023 - Here, a list comprehension [int(num) for num in re.findall(pattern, ''.join(string_list))] is used to convert the matched strings to integers. The regular expression pattern r"\d+" matches one or more consecutive digits in each element of the list ? import re def sum_numbers(string_list): pattern = r"\d+" numbers = [int(num) for num in re.findall(pattern, ''.join(string_list))] return sum(numbers) string_list = ['abc123', 'def456', 'ghi789'] result = sum_numbers(string_list) print(f"Sum of numbers: {result}")
🌐
EyeHunts
tutorial.eyehunts.com › home › python sum list of strings | example code
Python sum list of strings | Example code
September 11, 2023 - Where the given list may contain ... isinstance(element, int) or element.isdigit(): # adding the element to the total total += int(element) print(total) ......
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-strings-length-summation
Python | Strings length summation - GeeksforGeeks
May 10, 2023 - The sum function is used to find the summation of each string of list and list comprehension does the task of iteration. ... # Python3 code to demonstrate # string lengths summation # using sum() + list comprehension # initializing list of tuples ...
🌐
Finxter
blog.finxter.com › home › learn python blog › python sum() list – a simple illustrated guide
Python sum() List - A Simple Illustrated Guide - Be on the Right Side of Change
April 23, 2020 - Solution: Use the join() method of Python strings to concatenate all strings in a list. The sum() function works only on numerical input data.
🌐
Real Python
realpython.com › python-sum-function
Python's sum(): The Pythonic Way to Sum Values – Real Python
March 18, 2026 - Here, you use a list of strings as an argument and build a single string from the input. Note that .join() uses the string on which you call the method as a separator during the concatenation. In this example, you call .join() on a string that consists of a single space character (" "), so the original strings from greeting are separated by spaces in your final string. You can now use Python’s built-in function sum() to add multiple numeric values together.
🌐
TutorialsPoint
tutorialspoint.com › sum-of-list-with-string-types-in-python
Sum of list (with string types) in Python
random_list = [1, '10', 'tutorialspoint', '2020', 'tutorialspoint@2020', 2020] total = sum(int(element) for element in random_list if isinstance(element, int) or (isinstance(element, str) and element.isdigit())) print(total) ...
🌐
Designcise
designcise.com › web › tutorial › how-to-find-the-sum-of-a-list-of-integer-strings-in-python
How to Find the Sum of a List of Integer Strings in Python? - Designcise
October 14, 2022 - In Python, you can get the sum ... sum of a list of integer strings, you can do either of the following: Convert Integers Using map() Before sum(); Convert Integers Using List Comprehension Before sum()....
🌐
Finxter
blog.finxter.com › 5-best-ways-to-sum-a-list-with-string-types-in-python
5 Best Ways to Sum a List with String Types in Python – Be on the Right Side of Change
The code snippet converts each string into an integer within a new list and immediately aggregates these values with the sum() function to produce the total. Another straightforward approach is utilizing a for loop to iterate through each string element, convert it to an integer, and cumulatively ...
🌐
Flexiple
flexiple.com › python › python-sum-list
How to use Python to sum a list? | Flexiple Tutorials | Python - Flexiple
March 14, 2022 - A common error that arises while using the sum() function, is when the list contains a string. Since it is not possible to add int values in strings, Python returns a TypeError. Let us look at such an instance. #Creating a list of number and a string numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "10"] sum_numbers = sum(numbers) print(sum_numbers)
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-summation-of-numbers-in-string-list
Python - Get summation of numbers in string list - GeeksforGeeks
April 17, 2023 - In this, we run a loop on lists using list comprehension and extract summation using sum(). ... # Python3 code to demonstrate working of # Summation of String Integer lists # using sum() + int() + list comprehension # initialize list test_list = [['1', '4'], ['5', '6'], ['7', '10']] # printing original list print("The original list : " + str(test_list)) # Summation of String Integer lists # using sum() + int() + list comprehension res = [sum(int(ele) for ele in sub) for sub in test_list] # printing result print("List after summation of nested string lists : " + str(res))
🌐
Code Underscored
codeunderscored.com › sum-list-python
How to sum a list in Python | Code Underscored
May 5, 2021 - There are various ways to sum a lists’ elements in Python. We hope that by the end of this article, you would have mastered at least one approach that resonates with you more. Python has an inbuilt function called sum() which aids in adding up the numbers in a list.
🌐
Sololearn
sololearn.com › en › Discuss › 2463272 › does-sum-function-in-python-converts-the-output-into-string-or-is-the-return-type-of-sum-is-string
Does sum() function in Python converts the output into string? Or Is the return type of sum() is string?? | Sololearn: Learn to code for FREE!
That is for single number of string type.. Your input contains spaces so on that stage not possible... Add this before sum(ar) ar=[int(i) for i in ar ] Edit : ATSHAYA KUMAR.R s=0 for i in range(0,4): print("enter rupees:") ar=input().split() ar=[int(i) for i in ar ] a=sum(ar) s=s+a print(a) #but your code print last input sum only..
🌐
Reddit
reddit.com › r/codinghelp › i’m trying to print the sum of numbers in a list and can’t seem to figure it out.
r/CodingHelp on Reddit: i’m trying to print the sum of numbers in a list and can’t seem to figure it out.
March 2, 2021 - This is especially important for Python. input_string=input("Please enter seven integer numbers: ") List=input_string.split() print(List) #input takes string, but to add we need int/float integer_List=[] for i in List: integer_List.append(int(i))#creating a new list to store integer values print("integers: ",integer_List) integer_List.sort() print(integer_List) #to calculate the sum num_sum=sum(integer_List) #declaring counter variable print("Sum=",num_sum)
🌐
Tutorial Reference
tutorialreference.com › python › examples › faq › python-how-to-sum-lists-of-strings
How to Sum and Join List of Strings in Python | Tutorial Reference
While this approach works, str.join() ... is preferrable if it is possible for your use case. To sum the digits within a string, use a generator expression with the sum() function:...