Python: Listify the list of given strings individually using map function
3. Listify Strings Map
Write a Python program to listify the list of given strings individually using Python map.
Sample Solution:
Python Code :
# Create a list named 'color' containing strings representing colors
color = ['Red', 'Blue', 'Black', 'White', 'Pink']
# Print the original list of colors
print("Original list:")
print(color)
# Print a message indicating the operation to be performed
print("\nAfter listify the list of strings are:")
# Use the map function to apply the list function to each element of 'color'
result = list(map(list, color))
# Print the result of the map operation, converting each string to a list of characters
print(result)
Sample Output:
Original list: ['Red', 'Blue', 'Black', 'White', 'Pink'] After listify the list of strings are: [['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]
For more Practice: Solve these Related Problems:
- Write a Python program to convert each string in a list into a list of its individual characters using map.
- Write a Python program to split each string into a list of words (using space as a delimiter) using map.
- Write a Python program to convert each string to a list of its corresponding ASCII values using the map() function.
- Write a Python program to reverse each string and then convert it into a list of characters using map.
Go to:
Previous: Write a Python program to add three given lists using Python map and lambda.
Next: Write a Python program to create a list containing the power of said number in bases raised to the corresponding number in the index using Python map.
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.