The FORGOTTEN Function! #python #programming #coding

preview_player
Показать описание
This short shows an example of how to use the extend function in python to add a list to another list.

Background Music:
Creative Commons Attribution-ShareAlike 3.0 Unported
Рекомендации по теме
Комментарии
Автор

Yes, you can also do:
inventory += chest
Both += and extend() are in-place methods and both are suitable solutions for this. It’s personal preference.

b
Автор

Man as a C programmer this makes me rethink life choices

GameWorldRS
Автор

Don't forget to delete items from the chest, otherwise someone is getting infinite resources...

blood_lad
Автор

Everyones talking about other ways to do the same thing, but no ones talking about the fact that there are still items in the chest

joeldoonan-ketteringham
Автор

Thank you, @b001, so much for these shorts. They really drive home concepts and the community genuinely seems willing to add their various expertise to the discussions.

Aramakie
Автор

Never used extend before, however I do use:
inventory = intentory + chest
Works too

gertjanvandenbroek
Автор

I think
inventory += chest
also work

nickname_
Автор

Also known as concat in JS and Ruby: [1, 2, 3].concat([4, 5, 6])

Zeragamba
Автор

I never knew about this thank you so much for this knowledge

PyroCyclone-old
Автор

Wow. Something I have been using for a while is the right thing? I am proud. 😂

mohammedgt
Автор

This is awesome.
Currently learning python so liking it back to games makes it infinitely easier to learn.
Thanks much will keep this in mind from now

themagicalbeast
Автор

Thanks! I recently had this problem and my solution was:-

Inventory = Inventory + Chest

mobeen
Автор

Great video and it shows both ways. Some interviewers will ask you to do the same feature but without using built in methods and some interviewers may have ou write code in a text editor not in a IDE. Thank you awesome content.

laxlyfters
Автор

You also can merge them
Inventory = [*Inventory, *chest]

timofey
Автор

very helpful, thanks. Great format for learning

techpath
Автор

This is good for a "Pickup All" but the first option is better for individual items also drop the item from the array when it's picked up

Kadori
Автор

I love extend, very useful as I like dealing with and sorting data in my code :D

Wallee
Автор

I genuinely thought everyone used this

BlaqwD
Автор

Can't you also use the built in addition operator to just add the two lists together?

seano
Автор

In JS is += or the 3 dots mathod(...) simple

CC-.