"Larry Martell" wrote in message
news:CACwCsY5P47-dB1NLQTUTQ=0aF6B+-M3y4hCxcUGmcVmHM8=-x...@mail.gmail.com...
>I think I know the answer is no, but is there any package that allows
> creating a list with holes in it? E.g. I'd want to do something like:
>
> x[10
On Sat, Jan 4, 2014 at 2:32 PM, Dan Stromberg wrote:
> That is fine, sorting once at then end of a script is a good use of
> sorted(some_dict.keys()). However, it probably should be pointed out
> that this, while similar, is not so good:
>
> for thing in range(n):
>for key in sorted(some_dict
On Fri, Jan 3, 2014 at 7:00 PM, Chris Angelico wrote:
> On Sat, Jan 4, 2014 at 1:58 PM, Dan Stromberg wrote:
>> On Fri, Jan 3, 2014 at 7:37 AM, Chris Angelico wrote:
>>> Depending on what exactly you need, it's probably worth just using a
>>> dict. In what ways do you need it to function as a li
On Sat, Jan 4, 2014 at 1:58 PM, Dan Stromberg wrote:
> On Fri, Jan 3, 2014 at 7:37 AM, Chris Angelico wrote:
>> Depending on what exactly you need, it's probably worth just using a
>> dict. In what ways do you need it to function as a list? You can
>> always iterate over sorted(some_dict.keys())
On Fri, Jan 3, 2014 at 7:37 AM, Chris Angelico wrote:
> Depending on what exactly you need, it's probably worth just using a
> dict. In what ways do you need it to function as a list? You can
> always iterate over sorted(some_dict.keys()) if you need to run
> through them in order.
FWIW, sorting
On Fri, 03 Jan 2014 20:18:06 -0500, Roy Smith wrote:
> In article ,
> Larry Martell wrote:
>
>
>> Thanks, but I know all that about dicts. I need to use a list for
>> compatibility with existing code.
>
> Generalizing what I think the situation is, "A dict is the best data
> structure for the
On Sat, Jan 4, 2014 at 11:18 AM, Larry Martell wrote:
> Your last suggestion is what I ended up doing, but I had to key off
> the unit - I couldn't use because that
> isn't present for ones that have no - that messed me up for
> hours. But it's working now. Thanks all!
Sure, you know your dat
In article ,
Larry Martell wrote:
>
> Thanks, but I know all that about dicts. I need to use a list for
> compatibility with existing code.
Generalizing what I think the situation is, "A dict is the best data
structure for the parsing phase, but I need a list later to hand off to
legacy inte
On Fri, Jan 3, 2014 at 11:07 AM, Chris Angelico wrote:
> On Sat, Jan 4, 2014 at 2:55 AM, Larry Martell wrote:
>> The use case is that I'm parsing a XML file like this:
>>
>>
>>
>>
>> True
>>
>>
>>
>>
On Fri, Jan 3, 2014 at 1:07 PM, Denis McMahon wrote:
> On Fri, 03 Jan 2014 10:41:21 -0500, Larry Martell wrote:
>
>> The holes would be between the items I put in. In my example above, if I
>> assigned to [10] and [20], then the other items ([0..9] and [11..19])
>> would have None.
>
dic = {
On Fri, 03 Jan 2014 10:41:21 -0500, Larry Martell wrote:
> The holes would be between the items I put in. In my example above, if I
> assigned to [10] and [20], then the other items ([0..9] and [11..19])
> would have None.
>>> dic = { 10:6, 20:11}
>>> dic.get(10)
6
>>> dic.get(14)
>>> dic.get(27,
On Sat, Jan 4, 2014 at 2:55 AM, Larry Martell wrote:
> The use case is that I'm parsing a XML file like this:
>
>
>
>
> True
>
>
>
>
> False
>
>
In article ,
Chris Angelico wrote:
> Alternatively, if you expect to fill in most of the elements, it's
> possible you'd be happier working with a subclass of list that
> auto-expands by filling in the spare space with a singleton meaning
> "no element here".
And, if you know ahead of time the
On Sat, Jan 4, 2014 at 2:51 AM, Roy Smith wrote:
> In article ,
> Chris Angelico wrote:
>
>> Alternatively, if you expect to fill in most of the elements, it's
>> possible you'd be happier working with a subclass of list that
>> auto-expands by filling in the spare space with a singleton meaning
On Fri, Jan 3, 2014 at 10:37 AM, Chris Angelico wrote:
> On Sat, Jan 4, 2014 at 2:19 AM, Larry Martell wrote:
>> I think I know the answer is no, but is there any package that allows
>> creating a list with holes in it? E.g. I'd want to do something like:
>>
>> x[
On Sat, Jan 4, 2014 at 2:38 AM, Roy Smith wrote:
> Why do you want holes? Is the issue that you're storing sparse data and
> don't want to waste memory on unused keys? If so, a dictionary should
> do you fine.
>
> Do you need to be able to read the values back out in a specific order?
> You can
On Fri, Jan 3, 2014 at 10:30 AM, wrote:
> On Friday, January 3, 2014 4:19:09 PM UTC+1, larry@gmail.com wrote:
>> I think I know the answer is no, but is there any package that allows
>>
>> creating a list with holes in it? E.g. I'd want to do something like:
>
In article ,
Larry Martell wrote:
> I think I know the answer is no, but is there any package that allows
> creating a list with holes in it? E.g. I'd want to do something like:
>
> x[10] = 12
> x[20] = 30
Whenever you ask, "What data structure do I want",
On Sat, Jan 4, 2014 at 2:19 AM, Larry Martell wrote:
> I think I know the answer is no, but is there any package that allows
> creating a list with holes in it? E.g. I'd want to do something like:
>
> x[10] = 12
> x[20] = 30
>
> I'm thinking of something like de
On Friday, January 3, 2014 4:19:09 PM UTC+1, larry@gmail.com wrote:
> I think I know the answer is no, but is there any package that allows
>
> creating a list with holes in it? E.g. I'd want to do something like:
>
>
>
> x[10] = 12
>
> x[20] = 30
>
>
I think I know the answer is no, but is there any package that allows
creating a list with holes in it? E.g. I'd want to do something like:
x[10] = 12
x[20] = 30
I'm thinking of something like defaultdict but for lists (I know
that's very different, but ... )
Thanks!
-
21 matches
Mail list logo