Python Forum
How to capitalize in dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to capitalize in dictionary
#3
(Oct-27-2020, 04:30 PM)Larz60+ Wrote: You have lists for dictionary values, so must access each element in "grocery" and save back as value.title()
example:
pond_animals = {
    "fish": ["trout", "sumfish", "perch"],
    "amphibians": ["frogs", "salamanders", "snakes", "turtles"]
}

for n, value in enumerate(pond_animals["amphibians"]):
    pond_animals["amphibians"][n] = value.title()

print(pond_animals["amphibians"])
Output:
['Frogs', 'Salamanders', 'Snakes', 'Turtles']

Thank you for that! It was exactly what I was looking for!
Reply


Messages In This Thread
How to capitalize in dictionary - by Inkanus - Oct-27-2020, 03:00 PM
RE: How to capitalize in dictionary - by Larz60+ - Oct-27-2020, 04:30 PM
RE: How to capitalize in dictionary - by Inkanus - Oct-28-2020, 01:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find and replace to capitalize with Regex hermobot 2 2,542 Mar-21-2020, 12:30 PM
Last Post: hermobot
  [split] capitalize dict keys for display in string newbieAuggie2019 3 3,032 Oct-10-2019, 10:50 AM
Last Post: perfringo
  Python capitalize() method problem Skipper 9 10,729 Jan-27-2018, 03:11 PM
Last Post: Skipper

Forum Jump:

User Panel Messages

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