Python List Organization!!
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/...
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]
That's why learning data structures and algorithms is very important 😂
indx = foo.index("a")
foo[indx], foo[-1] = foo[-1], foo[indx]
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!
Wouldnt thst work using insert?
thank you for simplifying programming
Whhy not inv.remove("Gem") ?
This is gonna be more useful for times when the list is bigger since most of time you know it's index anyways
inv = ['gem', 'gem', 'gem']
print(inv.index('gem'))
>> 0
inv.remove("gem")
inv.append("gem")
Technically that's making a new string object whereas the video's method maintains the address of the original gem item
@@Kaazikinjust use cpp instead of you’re concerned about saving memory lol. Python isn’t fast enough to make it all worth it
@@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)
@@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.
@@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.
How can i see colors of () in my pycharm please
len = len(inv)
indx = inv.index(‘gem’)
inv.insert(len-1, inv.pop(indx)
print(inv)
Use find for more safety
don't mess with indices, when you haven't to
What is the time complexity
youtube i want these videos plz thank you algorithm
Also u can use slicing:
inv=inv[1:]+inv[:1]
Sure but "Gem" here can be in a different place than index 0
indx = foo.index("Gem")
foo[indx], foo[-1] = foo[-1], foo[indx]
@@sabrysmok but it wasn’t specified.
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?
why use O(1) 1 liner when O(N) 3 liner can do
or you could use the remove method.
I think you explain it in a difficult way.
this is not practically applicable. Poor coding.
What do you suggest?
a = [ 'gem' , 'sword' ,'health' ]
print(a)
pop = a.pop(0)
print(pop)
a.append(pop)
print(a)
is this good ?
Just wanted to add that it can be done as a oneliner inv.append(inv.pop(inv.index("Gem")))
O notation goes out the window
Bro , I need the theme you are using in this video.
Synthwave '84
What theme on replit are u using ?
It's not replit. It's VS Code and theme used in this video is Synthwave '84
what does line 8 do?
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
Nice
Why I need this I not understand why it's metter
But doesn't the append supposed to add the item at the front of the list ???
Nope, append adds to end of list
😂
Can you do a video or example video of pulling data or pattern matching from a file?
this is a very broad question. what type of file format, and what data?
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
or just use a database with the item and a position and also don't use python to develop a game... please
how do you just insert code like that?
Write the code, delete the code, then use ctrl + z to make it appear again.
make c# version for unity, i aint doing pygame
“Let’s say we are making a game”
>python
Oh no…