How to print the 2D lists for different values of n?
Suppose;
for n in range(0,3)
### different list viz.
when n =1, list1[ [ ],[ ] ]
when n =2, list2[ [ ],[ ] ]
when n =3, list3[ [ ],[ ] ]
now how to print this list? I think I've to create a new function , but how to do it??
1 Replies - 719 Views - Last Post: 26 January 2012 - 09:01 AM
#1
printing 2D list for different values of n from ' for ' loop
Posted 26 January 2012 - 08:48 AM
Replies To: printing 2D list for different values of n from ' for ' loop
#2
Re: printing 2D list for different values of n from ' for ' loop
Posted 26 January 2012 - 09:01 AM
Unlike some langauges, Python doesn't allow you to have variable variable names. However, what you can do is create a dictionary of lists:
An alternative is to create a three dimensional list:
list_dict = {
'list0': [[],[]],
'list1': [[],[]],
'list2': [[],[]]}
for i in range(3):
print(list_dict['list' + i])
An alternative is to create a three dimensional list:
list_list = [
[[],[]],
[[],[]],
[[],[]]]
for i in range(3):
print(list_list[i]))
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|