Python Forum
Capitalize first letter of names in nested loops
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Capitalize first letter of names in nested loops
#6
(Oct-25-2019, 03:11 PM)Larz60+ Wrote: change line 3 from
name.title()
To
name = name.title()

names=[['peter','jack','bo'],'eva',['christian','joanne',7],'5']
#Make all names in nested loop above with capital first letters, dont make new list but change current list
#elements 7 and '5' should be left as is

for list in names:
    for name in list:
        name = name.title()
        print(name)

print(names)
that does seem to make all but "eva" capital letters and prints: AttributeError: 'int' object has no attribute 'title'

which is probably as the list includes 7

furthermore, I cant print the list afterward. I don't think this for loop actually changes values within the names list?
Reply


Messages In This Thread
RE: Capitalize first letter of names in nested loops - by student_of_python - Oct-26-2019, 10:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with nested loops robert5502001 7 3,725 Aug-01-2022, 06:26 AM
Last Post: stevensanders
  computing average in nested loops cap510 5 5,266 Sep-11-2020, 12:33 PM
Last Post: deanhystad
  nested for loops to recursion ashkea26 4 3,570 Nov-02-2018, 05:00 PM
Last Post: ichabod801
  Nested loops in openCV JimmyJangle 1 4,882 Apr-17-2018, 04:10 AM
Last Post: Mekire
  capitalize all letters atux_null 5 3,963 Dec-03-2017, 07:07 PM
Last Post: buran
  Nested for loops with numbers Liquid_Ocelot 7 5,995 Aug-15-2017, 06:38 AM
Last Post: nilamo
  Nested loops, lists and if statements Liquid_Ocelot 10 9,147 Apr-23-2017, 02:02 PM
Last Post: Mekire
  Captalizing the letter from the first two names riko 6 6,423 Mar-10-2017, 10:11 PM
Last Post: riko

Forum Jump:

User Panel Messages

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