Python Forum
change only one element of list to upper case
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change only one element of list to upper case
#1
Hello

I am totally new to python and today learnt about lists, my question is how do i change the case of a particular element in a list

p=["mozzarella","cinderalla","salmonella"]

I want the list to be modified so cinderalla to be all caps



I tried this but not working

p[1]=p[1].upper()
Reply
#2
try again. it is working

>>> p=["mozzarella","cinderalla","salmonella"]
>>> p[1]=p[1].upper()
>>> p
['mozzarella', 'CINDERALLA', 'salmonella']
>>>
Reply
#3
Looks fine to me?
Output:
>>> p=["mozzarella","cinderalla","salmonella"] >>> p[1]=p[1].upper() >>> p ['mozzarella', 'CINDERALLA', 'salmonella']
Reply
#4
yes, my solution works :) maybe i got confused looking at a different error, thanks everyone for your reply..quick question is how do i clear the screen from the python interpretor, do i have to import anything
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  list in dicitonary element problem jacksfrustration 3 626 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  Change font in a list or tuple apffal 4 2,635 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 918 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Replace with upper(string) WJSwan 7 1,546 Feb-10-2023, 10:28 AM
Last Post: WJSwan
  Find (each) element from a list in a file tester_V 3 1,157 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,738 Oct-26-2022, 04:03 PM
Last Post: deanhystad
  How to change the datatype of list elements? mHosseinDS86 9 1,911 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,162 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  find some word in text list file and a bit change to them RolanRoll 3 1,482 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  How to find the second lowest element in the list? Anonymous 3 1,907 May-31-2022, 01:58 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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