Thursday, 23 September 2021

Python: Convert list of strings to list of list of characters

Using map, list functions, we can convert list of strings to the list of list of characters.

 

map_demo_3.py

data = ['Hello', 'How', 'Are', 'You']

print(list(map(list, data)))

 

Output

[['H', 'e', 'l', 'l', 'o'], ['H', 'o', 'w'], ['A', 'r', 'e'], ['Y', 'o', 'u']]

 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment