w3resource

Python: Listify the list of given strings individually using map function


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']]

Python Code Editor:

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

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.

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.