On Fri, Sep 16, 2011 at 8:02 AM, Vlastimil Brom
wrote:
> Besides the above sugestions to correct the nested list approach,
> if you need to set and access the data at the given "coordinates" you
> could also use a nested defaultdict...
The defaultdict is efficient for a sparse matrix, but I suspe
2011/9/15 Stef Mientki :
> hello,
>
> I need a nested list, like this
>
A= [ [None,None], [None,None], [None, None] ]
A[2][0] =77
A
> [[None, None], [None, None], [77, None]]
> ...
>
> thanks,
> Stef
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Besides the above suge
Stef,
Are your bottom-level lists always of length 2? If so, then you could
use an array, instead of a list of lists.
Python ships with a module called array, but it doesn't allow you to
put non-numeric types into arrays, and it looks like you want the
NoneType. I use the popular numpy module,
On 09/15/2011 09:57 AM, Stef Mientki wrote:
hello,
I need a nested list, like this
>>> A= [ [None,None], [None,None], [None, None] ]
>>> A[2][0] =77
>>> A
[[None, None], [None, None], [77, None]]
Because the list is much larger, I need a shortcut (ok I can use a for
loop)
So I tried
>>> B =
On Thu, 15 Sep 2011 18:57:24 +0200, Stef Mientki wrote:
[snip]
> Because the list is much larger, I need a shortcut (ok I can use a for loop)
> So I tried
> >>> B = 3 * [ [ None, None ]]
> >>> B[2][0] = 77
> >>> B
> [[77, None], [77, None], [77, None]]
>
> which doesn't work as expected.
>
> any su
>>> B = 3 * [ [ None, None ]]
That makes a list of the exact same list object: [ a, a, a ] where a = [ None,
None ].
Instead I would do something like (untested python2.x):
B = [ [ None, None ] for x in xrange(3) ]
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712
hello,
I need a nested list, like this
>>> A= [ [None,None], [None,None], [None, None] ]
>>> A[2][0] =77
>>> A
[[None, None], [None, None], [77, None]]
Because the list is much larger, I need a shortcut (ok I can use a for loop)
So I tried
>>> B = 3 * [ [ None, None ]]
>>> B[2][0] = 77
>>> B
[