Python List Organization!!

Sdílet
Vložit
  • čas přidán 2. 09. 2023
  • ⭐ Join the Byte Club to practice your Python skills! ($2.99/mo): / @b001
    🐦 Follow me on Twitter: / b001io
    Background Music:
    Mystic Mountain by Purrple Cat | purrplecat.com
    Music promoted by www.free-stock-music.com
    Creative Commons / Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
    creativecommons.org/licenses/...

Komentáře • 55

  • @MsWhiskey974
    @MsWhiskey974 Před 10 měsíci +126

    Also, in case you want to swap two items by values:
    a = inv.index('Gem')
    b = inv.index('Sword')
    i[b], i[a] = i[a], i[b]

  • @Amankhan-cl1dq
    @Amankhan-cl1dq Před 8 měsíci +20

    That's why learning data structures and algorithms is very important 😂

  • @sabrysm
    @sabrysm Před 8 měsíci +5

    indx = foo.index("a")
    foo[indx], foo[-1] = foo[-1], foo[indx]

  • @bloxymath1019
    @bloxymath1019 Před 10 měsíci +43

    Very cool! Sadly, this only works if you want to append to the END of the list, which was what the video was about, but there are easy fix-arounds to this! Awesome video nonetheless!

  • @DcBooper
    @DcBooper Před 10 měsíci +3

    thank you for simplifying programming

  • @SilverSuperGamer
    @SilverSuperGamer Před 5 dny +1

    Whhy not inv.remove("Gem") ?

  • @maksiksq
    @maksiksq Před 10 měsíci

    This is gonna be more useful for times when the list is bigger since most of time you know it's index anyways

  • @danilogsch
    @danilogsch Před 8 měsíci +3

    inv = ['gem', 'gem', 'gem']
    print(inv.index('gem'))
    >> 0

  • @joaogabrielsalvadorpaiva1649
    @joaogabrielsalvadorpaiva1649 Před 10 měsíci +44

    inv.remove("gem")
    inv.append("gem")

    • @Kaazikin
      @Kaazikin Před 10 měsíci +21

      Technically that's making a new string object whereas the video's method maintains the address of the original gem item

    • @JohnMeathead
      @JohnMeathead Před 10 měsíci +8

      @@Kaazikinjust use cpp instead of you’re concerned about saving memory lol. Python isn’t fast enough to make it all worth it

    • @yesil_hiyar7335
      @yesil_hiyar7335 Před 10 měsíci +1

      @@JohnMeatheadhe’s doing that bc normally you might have classes of items in an inventory that you’d like to retain the data for (such as amount of said item which may be stored in said classes)

    • @dputra
      @dputra Před 9 měsíci

      ​​@@JohnMeathead not every problem is a nail and not every problem can be solved with a hammer. I would definitely avoid cpp to build a webapp or AI/ML stuffs.

    • @jm-lc3jp
      @jm-lc3jp Před 13 dny

      @@Kaazikin It's an assumption that he would even need to maintain the address. Maybe he doesn't care. In 99.9% of cases no one would care.

  • @hajeahajda6325
    @hajeahajda6325 Před 9 měsíci

    How can i see colors of () in my pycharm please

  • @Rossilorenzo-yf7oq
    @Rossilorenzo-yf7oq Před 4 měsíci

    len = len(inv)
    indx = inv.index(‘gem’)
    inv.insert(len-1, inv.pop(indx)
    print(inv)

  • @user-cp7yw6ho8r
    @user-cp7yw6ho8r Před 6 měsíci

    Use find for more safety

  • @nurotn
    @nurotn Před 6 měsíci

    don't mess with indices, when you haven't to

  • @AbidAnsari-tl2sx
    @AbidAnsari-tl2sx Před 9 měsíci

    What is the time complexity

  • @somethingmysterious1135
    @somethingmysterious1135 Před 8 měsíci

    youtube i want these videos plz thank you algorithm

  • @AngryEgg6942
    @AngryEgg6942 Před 8 měsíci

    Also u can use slicing:
    inv=inv[1:]+inv[:1]

    • @sabrysm
      @sabrysm Před 8 měsíci

      Sure but "Gem" here can be in a different place than index 0

    • @sabrysm
      @sabrysm Před 8 měsíci

      indx = foo.index("Gem")
      foo[indx], foo[-1] = foo[-1], foo[indx]

    • @AngryEgg6942
      @AngryEgg6942 Před 8 měsíci

      @@sabrysmok but it wasn’t specified.

  • @paultapping9510
    @paultapping9510 Před 8 měsíci

    but then you'd wrap that into a function that takes an argument of the item name, to give you a function that can move any item, right?

  • @iaingavinsoutherland4369
    @iaingavinsoutherland4369 Před 10 měsíci

    why use O(1) 1 liner when O(N) 3 liner can do

  • @Abel703
    @Abel703 Před 7 měsíci

    or you could use the remove method.

  • @WinnerSingh
    @WinnerSingh Před 10 měsíci +1

    I think you explain it in a difficult way.

  • @_Caose
    @_Caose Před 10 měsíci +9

    this is not practically applicable. Poor coding.

    • @sabrysm
      @sabrysm Před 8 měsíci

      What do you suggest?

  • @mdyusufansari8897
    @mdyusufansari8897 Před 2 měsíci

    a = [ 'gem' , 'sword' ,'health' ]
    print(a)
    pop = a.pop(0)
    print(pop)
    a.append(pop)
    print(a)
    is this good ?

  • @christian1233211000
    @christian1233211000 Před 10 měsíci +6

    Just wanted to add that it can be done as a oneliner inv.append(inv.pop(inv.index("Gem")))

  • @digvijaybokey3585
    @digvijaybokey3585 Před 8 měsíci

    O notation goes out the window

  • @mohammedelprince4506
    @mohammedelprince4506 Před 8 měsíci

    Bro , I need the theme you are using in this video.

  • @itswestm8602
    @itswestm8602 Před 8 měsíci

    What theme on replit are u using ?

    • @soumyaranjanrout2843
      @soumyaranjanrout2843 Před 7 měsíci

      It's not replit. It's VS Code and theme used in this video is Synthwave '84

  • @itzdamian4078
    @itzdamian4078 Před 8 měsíci +1

    what does line 8 do?

    • @samoerai6807
      @samoerai6807 Před 8 měsíci +1

      It selects the item you want to remove from the list just to append it later. You could also write line 8 as an input value so the user can print the list and then choose what item should be moved to the bottom of the list
      Hopefully it helps

  • @claudiocesarmontenegrojuni5141
    @claudiocesarmontenegrojuni5141 Před 10 měsíci +1

    Nice

  • @shalevforfor5550
    @shalevforfor5550 Před 9 měsíci

    Why I need this I not understand why it's metter

  • @shivamprajapati3010
    @shivamprajapati3010 Před 9 měsíci

    But doesn't the append supposed to add the item at the front of the list ???

  • @Tempestgodyt
    @Tempestgodyt Před 5 měsíci

    😂

  • @mcgriddletime915
    @mcgriddletime915 Před 10 měsíci +1

    Can you do a video or example video of pulling data or pattern matching from a file?

    • @HorridModz
      @HorridModz Před 10 měsíci

      this is a very broad question. what type of file format, and what data?

  • @1zychan51
    @1zychan51 Před 10 měsíci

    1. It works only with the end of the list
    2. It doesn't work as you want if you have for example two gems in inventory

  • @frederik_hd
    @frederik_hd Před 10 měsíci

    or just use a database with the item and a position and also don't use python to develop a game... please

  • @ExotErr
    @ExotErr Před 10 měsíci

    how do you just insert code like that?

    • @casperdh
      @casperdh Před 10 měsíci +3

      Write the code, delete the code, then use ctrl + z to make it appear again.

  • @gutsjoestar7450
    @gutsjoestar7450 Před 10 měsíci +1

    make c# version for unity, i aint doing pygame

  • @BitTheByte
    @BitTheByte Před 7 měsíci

    “Let’s say we are making a game”
    >python
    Oh no…