Python: Convert a list of integers, tuple of integers in a list of strings
Python map: Exercise-8 with Solution
Write a Python program to convert a given list of integers and a tuple of integers in a list of strings.
Sample Solution:
Python Code :
nums_list = [1,2,3,4]
nums_tuple = (0, 1, 2, 3)
print("Original list and tuple:")
print(nums_list)
print(nums_tuple)
result_list = list(map(str,nums_list))
result_tuple = tuple(map(str,nums_tuple))
print("\nList of strings:")
print(result_list)
print("\nTuple of strings:")
print(result_tuple)
Sample Output:
Original list and tuple: [1, 2, 3, 4] (0, 1, 2, 3) List of strings: ['1', '2', '3', '4'] Tuple of strings: ('0', '1', '2', '3')
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to add two given lists and find the difference between lists. Use map() function.
Next: Write a Python program to create a new list taking specific elements from a tuple and convert a string value to integer.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Performs left-to-right function composition.
Example:
from functools import reduce def tips_compose_right(*fns): return reduce(lambda f, g: lambda *args: g(f(*args)), fns) add = lambda x, y: x + y square = lambda x: x * x add_and_square = tips_compose_right(add,square) print(add_and_square(5, 2))
Output:
49
- 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