# printing 2D list for different values of n from ' for ' loop

Page 1 of 1

## 1 Replies - 1332 Views - Last Post: 26 January 2012 - 09:01 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=264311&amp;s=858893b94e1a1817f77a73be6672525d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jone kim

Reputation: 2
• Posts: 49
• Joined: 07-January 10

# printing 2D list for different values of n from ' for ' loop

Posted 26 January 2012 - 08:48 AM

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??
Is This A Good Question/Topic? 0

## Replies To: printing 2D list for different values of n from ' for ' loop

### #2 Motoma

Reputation: 452
• Posts: 797
• Joined: 08-June 10

## 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:
```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]))

```