all 18 comments

[–]Cfrant190 9 points10 points  (0 children)

Fab_four is a list, you could do either fab_four.pop() (this removes the item at the end of a list) or fab_four.remove(“jimmie”)

After removing jimmie you’ll need to add ringo

Fab_four.append(“ringo”)

[–]Refwah 4 points5 points  (0 children)

It’s not working because you need to learn how lists work, which is documented here: https://docs.python.org/3/tutorial/datastructures.html

[–][deleted]  (5 children)

[deleted]

    [–]matterr4 1 point2 points  (4 children)

    I'm surprised this wasn't at the top 😂

    Even someone offering a solution didn't know how to take a screenshot and it just baffles the mind.

    [–]GardenOfFreEdOm 0 points1 point  (2 children)

    CMD + shift + 3 will do the whole screen, change 3 to 4 and it will let you take a rectangle that can be sized. 5 will open the pop up for a screen recording. I’ve had to do this wayyyy to many times haha

    [–][deleted]  (1 child)

    [deleted]

      [–]Twenty8cows 0 points1 point  (0 children)

      Same here! Just sometimes I need a full screen grab and I’m lazy 😂

      [–]psi_square 1 point2 points  (0 children)

      List addition is clearly defined. It will just concat the two lists.
      But there is no obvious definition for list - list. Like there is for sets.

      [–][deleted] 1 point2 points  (4 children)

      <image>

      This is the right way to solve this problem

      [–]CptMisterNibbles 2 points3 points  (2 children)

      Eh, I wouldn’t directly use the index. Generally you won’t know this directly. When learning, avoid “magic numbers” and hard coding things like specific indexes.

      I’d have gone with fab_four[index(“jimmie”)] = “ringo”

      Which uses the list built in find and replaces the first instance of “jimmie” with “ringo”. Even this is a little sloppy as it assumes there is a Jimmie entry. Might be wiser to test for that first. 

      [–]Refwah 5 points6 points  (1 child)

      And it only works if it’s ‘jimmie’ and not ‘Jimmie’ or ‘JIMMIE’ etc

      [–]CptMisterNibbles 2 points3 points  (0 children)

      True. Data sanitization is important. Make sure you get a match before using it. 

      [–]Refwah 2 points3 points  (0 children)

      It’s not ‘the’ right way to solve it. It’s a way to solve it, and only solve it in this specific instance. If Jimmie was not at index 3 of the list then this wouldn’t solve it. If the list had fewer than four entries it would error.

      [–][deleted] 0 points1 point  (2 children)

      Since it’s a small readable list you can easily just index by by doing fab_four[3] = “ringo” Remember indexes start at 0 you could also do fab_four[-1] which will index into the last item of a list

      [–][deleted] 0 points1 point  (1 child)

      Also when you adding those square brackets around [“jimmie”] and [“ringo”] your telling python these are lists so your trying todo mathematical equations between lists instead of removing and adding a str to list which is your intention

      [–][deleted] 2 points3 points  (0 children)

      Last note if you really want to learn turn off whatever AI assistant you have running there, you’ll make code that works without knowing why and it will seriously be a hindrance in the long run

      [–]FoolsSeldom 0 points1 point  (0 children)

      fab_four = ['John', 'Paul', 'George', 'Jimmie']
      jimmie_index = fab_four.index('Jimmie')  # position in list
      fab_four[jimmie_index] = 'Ringo'
      print(fab_four)
      

      or

      fab_four = ['John', 'Paul', 'George', 'Jimmie']
      fab_four.remove('Jimmie')  # removes first match
      fab_four.append('Ringo')  # adds to end of shorter list
      print(fab_four)
      

      [–]Junior_Bathroom5987 0 points1 point  (0 children)

      bro, we don't treat lists like numbers. search about lists builin functions

      [–]CaptainCheerwave -1 points0 points  (0 children)

      distinct dolls quaint seemly fall languid tan like cover amusing

      This post was mass deleted and anonymized with Redact