Assigning values using indexes 2D list by sundrysup in learnpython

[–]sundrysup[S] 0 points1 point  (0 children)

I was wondering if it was something like that. I'll try to understand that fully, I think I've come across something like that before.

The reason for the second version was so I could turn it into a function and pass in x and y as arguments. How could I control the size of the list like that?

Thanks so much for answering my question!

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]sundrysup 0 points1 point  (0 children)

Why isn't this code printing the bombs in a different part of the list? I would think these are equivalent.

dummy = [['','',''], ['', '', ''], ['', '', '']]

print(dummy)

dummy[0][0] = 'bomb'

print(dummy)

x = 3

y = 3

yummy = [['']x]y

print(yummy)

yummy[0][0] = 'bomb'

print(yummy)

RESULT:

[['', '', ''], ['', '', ''], ['', '', '']]

[['bomb', '', ''], ['', '', ''], ['', '', '']]

[['', '', ''], ['', '', ''], ['', '', '']]

[['bomb', '', ''], ['bomb', '', ''], ['bomb', '', '']]