I was wondering if there was a one-liner in Python that would allow me to get the first character out of every string in a given list in Python. I can accomplish this task with the following code, however I was hoping there was a cleaner way to do it. By cleaner I mean using a built-in function, or using a one-liner that accomplishes the same thing as this for
loop. Please let me know if there is a cleaner way and if I need to clarify anything further.
names = ['Sally', 'Tom']
firstCharList = []
for name in names:
firstCharList.append(name[0])
print(firstCharList)
Output: ['S', 'T']