names = ['one', 'two']
print([n[0].upper() for n in names])
I want output like this: One, Two
how can I do this with python?
names = ['one', 'two']
print([n[0].upper() for n in names])
I want output like this: One, Two
how can I do this with python?
>>> names = ['one', 'two']
>>> names = [n.title() for n in names]
>>> names
['One', 'Two']
>>>
If you want it to work with a capital letter in it like oNe
will be ONe
then:
>>> names = ['oNe', 'twO']
>>> names = [n[0].upper()+n[1:] if n else "" for n in names]
>>> names
['ONe', 'TwO']
>>>
You need to use the method 'capitalize()' of the Python Standard Library.Here is the code :
names = ['one', 'two']
print([n.capitalize() for n in names])
So, you will get this output: ['One', 'Two']