1

I have a nested list, and I'm trying to capitalize all the titles (the third element in each nested list i.e. cardinal richelieu etc.).

Can't seem to wrap my head around the right approach. I thought replace would work, but I'm getting an error: TypeError: replace() argument 2 must be str, not builtin_function_or_method

Below - nested lists, followed by my attempt at replace. I appreciate any help to understand what I'm doing wrong!

    [['j234hg', '19 October 1969', 'court scene with cardinal richelieu'], ['d45j5jkd', '28 December 1969', 'THE ROYAL PHILHARMONIC ORCHESTRA GOES TO THE BATHROOM'], ['s4k5jk', '8 December 1970', 'crossing the atlantic on a tricycle'], ['zd7u4h', '19 October 1969', 'Bicycle Repair Man'], ['f983', '22 December 1970', 'Royal Episode 13 (or: The Queen Will Be Watching)'], ['j8s74', '15 September 1970', 'THE SEMAPHORE VERSION OF WUTHERING HEIGHTS'], ['n4j6l3j', '7 December 1972', 'Mr. Pither']]    

    records_list = [[x.replace(i[2], i[2].title) for x in i] for i in records_list]
Barbaros Özhan
  • 47,993
  • 9
  • 26
  • 51
  • 1
    You could've just done `[x.title() for x in i]` for the inner list and it would've worked. Yeah, you also have to call the function. – cs95 Mar 06 '18 at 17:23
  • WOW ... thank you! So simple and I just couldn't quite get there. Appreciate the help so much! – Sarah Fletcher Mar 06 '18 at 17:26
  • 1
    Possible duplicate of [Convert a Python list with strings all to lowercase or uppercase](https://stackoverflow.com/questions/1801668/convert-a-python-list-with-strings-all-to-lowercase-or-uppercase) – jpp Mar 06 '18 at 17:31
  • ^not an *exact* duplicate but sufficient. – jpp Mar 06 '18 at 17:31

0 Answers0