w3resource

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

Python map: Exercise-3 with Solution

Write a Python program to listify the list of given strings individually using Python map.

Sample Solution:

Python Code :

color = ['Red', 'Blue', 'Black', 'White', 'Pink'] 
print("Original list: ")
print(color) 
print("\nAfter listify the list of strings are:") 
result = list(map(list, color)) 
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 Python skills with w3resource's quiz


Python: Tips of the Day

Returns the n maximum elements from the provided list. If n is greater than or equal to the provided list's length, then return the original list (sorted in descending order)

Example:

def tips_max_n(lst, n=1):
  return sorted(lst, reverse=True)[:n]
print(tips_max_n([1, 3, 5]))
print(tips_max_n([1, 3, 5], 2))

Output:

[5]
[5, 3]