-1
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?

2 Answers2

6
>>> 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']
>>> 
Black Thunder
  • 6,215
  • 5
  • 27
  • 56
1

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

codrelphi
  • 1,077
  • 1
  • 7
  • 12