Python Forum
make a list of string in capital by using a function
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
make a list of string in capital by using a function
#1


hi,thanks for looking my post

for now i am able to fulfill it through a lambada funtion:

l = ['java','python','c++'] #a list of string
a = list(map(lambda x: x.title() ,l)) #using map and title funtion upper every first letter
a

anyway,i really want to know how to achieve it without lambda funtion,like define a funtion first then using the 'map'
i tried but none of these works

def title1(x): #define a function name title1
c=x.title()
return c

can anyone point out what;s the matter with my code?thanks
Reply
#2
you can load the package titlestring, and then:
>>> from titlecase import titlecase
>>> titlecase('i want title case on this string')
'I Want Title Case on This String'
>>>
Reply
#3
list comp
>>> l = ['java','python','c++'] 
>>> [x.title() for x in l]
['Java', 'Python', 'C++']
Recommended Tutorials:
Reply
#4
@ananbc
You should avoid filter, map and reduce.
Take "List Comprehension"
See https://www.python-course.eu/list_comprehension.php
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,258 May-22-2023, 10:39 PM
Last Post: ICanIBB
  help me to make my password list in python >>> Oktay34riza 0 552 Dec-23-2022, 12:38 PM
Last Post: Oktay34riza
  Convert a string to a function mikepy 8 2,421 May-13-2022, 07:28 PM
Last Post: mikepy
  Make Groups with the List Elements quest 2 1,935 Jul-11-2021, 09:58 AM
Last Post: perfringo
Question How to make a 3D List of Excel Spreadsheets? chatguy 4 2,679 Jan-24-2021, 05:24 AM
Last Post: buran
  Undo interation to make a single list? DustinKlent 2 2,133 Nov-29-2020, 03:41 AM
Last Post: DustinKlent
  How to make global list inside function CHANKC 6 2,979 Nov-26-2020, 08:05 AM
Last Post: CHANKC
  How do i make a new lists out of an list ozezn1 1 1,664 Oct-28-2020, 10:19 PM
Last Post: Gribouillis
  Make list of dates between today back to n days Mekala 3 2,339 Oct-03-2020, 01:01 PM
Last Post: ibreeden
  How to make a list of values from a dictionary list? faryad13 2 2,016 Sep-03-2020, 03:45 PM
Last Post: faryad13

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020