Python 3 Programming Tutorial - Multi-dimensional List

preview_player
Показать описание
In this Python 3 programming tutorial, we cover the multi-dimensional list. Up until now, we have focused on single dimensional lists, but this is limiting. In programming, we are able to create lists with infinite depth. Here's how!

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Рекомендации по теме
Комментарии
Автор

youre better that my teacher sometimes, you know who to explain this

Daniel_Gomez
Автор

1:20
"Anybody see what I did there?"
Hah, it was hard to miss. I thought it was just a subconcious mistake until you did [2, 5]

Kyle-fytb
Автор

This was hugely helpful for a project I was working on. Thank you.

jobygaines
Автор

I'm new to programming and you sir have the best teaching method that I watched on YouTube, unlike others and also my professor HAHAHHA THANK-YOU SIR!
- 1st year college student from Philippines :)

setsunaPH
Автор

Your a life savior man, never ever take an online summer computer class, aint learning shit!

JediSteak
Автор

This will show how to print each single value for a Three Dimensional List :
#List - Next to each Value number (0, 0, 0) refers to the numbers you need to change within the []'s in the print statement
threeDimensionalList = [[['Value 1(0, 0, 0)', 'Value 2(0, 0, 1)'], ['Value 3(0, 1, 0)', 'Value 4(0, 1, 1)']], [['Value 5(1, 0, 0)', 'Value 6(1, 0, 1)'], ['Value 7(1, 1, 0)', 'Value 8(1, 1, 1)']], [['Value 9(2, 0, 0)', 'Value 10(2, 0, 1)'], ['Value 11(2, 1, 0)', 'Value 12(2, 1, 1)']]]
print('print Three Dimensional List values: ',

yankeeownz
Автор

Wow

My teacher is very good at python and computers but when I asked about 2d lists he just said "It's too complicated you need a lot of python background before you can do that "
and when I finally convinced him to teach me about it he did it in a way that I didn't understand at all.
Then I watched this video and now I understand it perfectly.

britishsoldier
Автор

Congratulation Dude! For the best material about Python that ever be on the youtube! You are awesome

mlo
Автор

It's a shame that python doesn't have a f unction like DIM in old style basic.
i.e. In basic you could go ....
dim a$(100, 10)
print a$(47, 1)

Basically DIM would initialize 100 rows x 10 columns of data that could be say 256 characters long [just a guess at the limit]. In other words 100 x 10 x 256 bytes allocated. This made setting up, addressing, storing so much easier in many ways
Of course if you went over your array settings, you'd spit an error and crash most likely.

With formatting, I've sometimes written something in basic, captured the output then copy / pasted it across.
I was writing something that had 5 co-ordinates for each set of data and about 1200 sets of data. For this, it was much easy to go to basic and go....
a1 = read a$
a2 = read a$
a3 = read a$
a4 = read a$
a5 = read a$
print "["+ "[" +a1 + etc etc

data 3, 4, 5, 3, 2, 6, 6, 6, 6, 4, 3, 2, 2, 0, 5 etc etc

Thanks. Your video helped with multi dimensional lists

roadmonitoroz
Автор

Your explanations are great but it could have been better if you could just use unique combination of numbers for each of the brackets, as I am little confused right now. But got the basics though. Thanks!

Reazul
Автор

I could not conceptualize this at all! Thank you so much

whyarealllnamestaken
Автор

your the best thanks for help with my homework thanks you have helped an awful lot

damienwilkok
Автор

"otherwise i'm gonna cry"

timothyso
Автор

try this: def func(*args):
print(list(args))

then you can manipulate args while it's a list :)

Orange-sohv
Автор

Thanks. Im learning python, and creating a billiards game. I want each pool ball to have a set of parameters expressed as a list. This will help get me to the point where I can automate the creation of the billiards balls. 😄

slickwillie
Автор

hi, can you please make a tutorial on how to create a 2D array using for loops and two inputs defining the 2 dimension?
thank you

chihabgoku
Автор

Here's my code for 2D list in python which would read no. of rows from the input :

empty = []
row = int(input())

for i in range(row):
temp = list(map(int, input().split()))
empty.append(temp)

for i in empty:
for j in i:
print(j, end=' ')
print('')

SourceCode
Автор

I'm not so new to programming and not so new to multi dimentional lists neither.
But python behaves very strangely to my code.


This is a sample:
>>> tb = [[""]*2]*3
>>> print(tb)
[['', ''], ['', ''], ['', '']]
>>> tb[0][0] = 0
>>> print(tb)
[[0, ''], [0, ''], [0, '']]
>>> tb[0][1] = 1
>>> print(tb)
[[0, 1], [0, 1], [0, 1]]
>>> tb[1][0] = 2
>>> print(tb)
[[2, 1], [2, 1], [2, 1]]
>>> tb[1][1] = 3
>>> print(tb)
[[2, 3], [2, 3], [2, 3]]

It is crushing everything like it considers only the last index should be taken in account.
Why is that ?
I must say that the above code is for trial because I obviously tried my code with loops first.

The same kind of code works perfectly in Java.

package essais;

public class MultiDimTables {
public static void main(String...args){
String[][] tb = new String[10][2];

for (int i=0;i<10;i++){
for (int j = 0; j < 2; j++) {
tb[i][j] = "[i: "+i+", j: "+j+"]";
}
}


for (int i=0;i<10;i++){
for (int j = 0; j < 2; j++) {

}
}
}
}

OUTPUT:
Populating...
Printing...
[i: 0, j: 0]
[i: 0, j: 1]
[i: 1, j: 0]
[i: 1, j: 1]
[i: 2, j: 0]
[i: 2, j: 1]
[i: 3, j: 0]
[i: 3, j: 1]
[i: 4, j: 0]
[i: 4, j: 1]
[i: 5, j: 0]
[i: 5, j: 1]
[i: 6, j: 0]
[i: 6, j: 1]
[i: 7, j: 0]
[i: 7, j: 1]
[i: 8, j: 0]
[i: 8, j: 1]
[i: 9, j: 0]
[i: 9, j: 1]

Process finished with exit code 0

Can someone explain to me what's wrong with my Python code or reasoning?

P.S. : Did some research. Got it. The way it works in Python sucks.
Initialising the way I did is actually referencing 3 times the same list of 2 elements. Hence if you change any element of the same list, the "others" (which are actually the same) updates together.
This sucks but once you know you'll be careful.
How to proceed is like this:
[[""] * 2 for i in range(3)]
Replace 2 and 3 by any number or variable if needs be.

EminoMeneko
Автор

Cool helped me ! But it should look like below. Your third line [7, 2], [2, 5] is in the second dimension. And print [2][0][0] would give an error. I tried it ;)
 x =[
[[5, 7], [6, 6]],
[[6, 6], [7, 8]],
[7, 2],
[2, 5],
]

luckies
Автор

That's very helpful to understand. Thank you!

jessicas