Python Forum

Full Version: can i nest dictionary in array?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In my last post ,I talked about saving all object location in variable and save it too a file,but they answer that doing things with file is one of the most slowest thing a computer can do(cause game to be slow),so I found a new way as an alternative,but I also have another problem.

Can I nest dictionaries in an array?
If so,can I use
array.append(dictionary)

I saw many people browsing this thread,but none of you is answering,why?
Do you mean array.array or this:

In [1]: l = []

In [2]: for k in range(1, 11):
    ...:     l.append({k: k**2})
    ...:     

In [3]: l
Out[3]: 
[{1: 1},
 {2: 4},
 {3: 9},
 {4: 16},
 {5: 25},
 {6: 36},
 {7: 49},
 {8: 64},
 {9: 81},
 {10: 100}]
(Feb-01-2017, 12:00 PM)hsunteik Wrote: [ -> ]In my last post ,I talked about saving all object location in variable and save it too a file,but they answer that doing things with file is one of the most slowest thing a computer can do(cause game to be slow),so I found a new way as an alternative,but I also have another problem.

Can I nest dictionaries in an array?
If so,can I use
array.append(dictionary)

I saw many people browsing this thread,but none of you is answering,why?

Yes, you can.

Note that using files and arrays are two orthogonal issues, the array won't survive the program stopping.