
Perhaps this has been brought up in the past but I couldn't find it in the archives: far too often I use the idiom dict(zip(keys,values)), or the same with izip. How does letting dict take two positional arguments sound ? Pros: - Pretty obvious semantics, no mental overhead to learn and remember it. - More concise (especially if one imports itertools just to use izip). - At least as efficient as the current alternatives. - Backwards compatible. Cons: - ?? George

George Sakkis wrote: > Perhaps this has been brought up in the past but I couldn't find it in > the archives: far too often I use the idiom dict(zip(keys,values)), or > the same with izip. How does letting dict take two positional > arguments sound ? > > Pros: > - Pretty obvious semantics, no mental overhead to learn and remember it. > - More concise (especially if one imports itertools just to use izip). > - At least as efficient as the current alternatives. > - Backwards compatible. > > Cons: - Yet Another Way To Do It - Marginal benefit Also note that the keyword variant is longer than the zip variant e.g. dict(zip(keys, values)) dict(keys=keys, values=values) and the relationship between the keys and values seems far less obvious to me in the keyword variant. Cheers, Brian

On 2/1/07, Brian Quinlan <brian@sweetapp.com> wrote: > George Sakkis wrote: > > Perhaps this has been brought up in the past but I couldn't find it in > > the archives: far too often I use the idiom dict(zip(keys,values)), or > > the same with izip. How does letting dict take two positional > > arguments sound ? > > > > Pros: > > - Pretty obvious semantics, no mental overhead to learn and remember it. > > - More concise (especially if one imports itertools just to use izip). > > - At least as efficient as the current alternatives. > > - Backwards compatible. > > > > Cons: > - Yet Another Way To Do It > - Marginal benefit > > Also note that the keyword variant is longer than the zip variant e.g. > > dict(zip(keys, values)) > dict(keys=keys, values=values) > > and the relationship between the keys and values seems far less obvious > to me in the keyword variant. > > Cheers, > Brian > Um, you do realize that dict(keys=keys, values=values) is already valid and quite different from dict(zip(keys, values)), don't you ? :) George

George Sakkis wrote:
Um, you do realize that dict(keys=keys, values=values) is already valid and quite different from dict(zip(keys, values)), don't you ? :)
Sorry, minor misreading on my part. Like that time in Sunday school when I missed the "not" in "Though shall not kill". That was a rough week for everyone involved. OK, the non-zip variant saves you 5 characters i.e. dict(zip(keys, values)) vs. dict(keys, values) I still don't like it :-) Cheers, Brian

Brian Quinlan wrote: > George Sakkis wrote: >> Perhaps this has been brought up in the past but I couldn't find it in >> the archives: far too often I use the idiom dict(zip(keys,values)), or >> the same with izip. How does letting dict take two positional >> arguments sound ? >> >> Pros: >> - Pretty obvious semantics, no mental overhead to learn and remember it. >> - More concise (especially if one imports itertools just to use izip). >> - At least as efficient as the current alternatives. >> - Backwards compatible. >> >> Cons: > - Yet Another Way To Do It > - Marginal benefit > > Also note that the keyword variant is longer than the zip variant e.g. > > dict(zip(keys, values)) > dict(keys=keys, values=values) > > and the relationship between the keys and values seems far less obvious > to me in the keyword variant. > Unfortunately dict(keys=keys, values=values) == {keys: values} regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007

Andrew Koenig wrote:
Of course I should really have written dict(keys=keys, values=values) != dict(zip(keys, values)) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007

George Sakkis wrote: > Perhaps this has been brought up in the past but I couldn't find it in > the archives: far too often I use the idiom dict(zip(keys,values)), or > the same with izip. How does letting dict take two positional > arguments sound ? > > Pros: > - Pretty obvious semantics, no mental overhead to learn and remember it. > - More concise (especially if one imports itertools just to use izip). > - At least as efficient as the current alternatives. > - Backwards compatible. > > Cons: - Yet Another Way To Do It - Marginal benefit Also note that the keyword variant is longer than the zip variant e.g. dict(zip(keys, values)) dict(keys=keys, values=values) and the relationship between the keys and values seems far less obvious to me in the keyword variant. Cheers, Brian

On 2/1/07, Brian Quinlan <brian@sweetapp.com> wrote: > George Sakkis wrote: > > Perhaps this has been brought up in the past but I couldn't find it in > > the archives: far too often I use the idiom dict(zip(keys,values)), or > > the same with izip. How does letting dict take two positional > > arguments sound ? > > > > Pros: > > - Pretty obvious semantics, no mental overhead to learn and remember it. > > - More concise (especially if one imports itertools just to use izip). > > - At least as efficient as the current alternatives. > > - Backwards compatible. > > > > Cons: > - Yet Another Way To Do It > - Marginal benefit > > Also note that the keyword variant is longer than the zip variant e.g. > > dict(zip(keys, values)) > dict(keys=keys, values=values) > > and the relationship between the keys and values seems far less obvious > to me in the keyword variant. > > Cheers, > Brian > Um, you do realize that dict(keys=keys, values=values) is already valid and quite different from dict(zip(keys, values)), don't you ? :) George

George Sakkis wrote:
Um, you do realize that dict(keys=keys, values=values) is already valid and quite different from dict(zip(keys, values)), don't you ? :)
Sorry, minor misreading on my part. Like that time in Sunday school when I missed the "not" in "Though shall not kill". That was a rough week for everyone involved. OK, the non-zip variant saves you 5 characters i.e. dict(zip(keys, values)) vs. dict(keys, values) I still don't like it :-) Cheers, Brian

Brian Quinlan wrote: > George Sakkis wrote: >> Perhaps this has been brought up in the past but I couldn't find it in >> the archives: far too often I use the idiom dict(zip(keys,values)), or >> the same with izip. How does letting dict take two positional >> arguments sound ? >> >> Pros: >> - Pretty obvious semantics, no mental overhead to learn and remember it. >> - More concise (especially if one imports itertools just to use izip). >> - At least as efficient as the current alternatives. >> - Backwards compatible. >> >> Cons: > - Yet Another Way To Do It > - Marginal benefit > > Also note that the keyword variant is longer than the zip variant e.g. > > dict(zip(keys, values)) > dict(keys=keys, values=values) > > and the relationship between the keys and values seems far less obvious > to me in the keyword variant. > Unfortunately dict(keys=keys, values=values) == {keys: values} regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007

Andrew Koenig wrote:
Of course I should really have written dict(keys=keys, values=values) != dict(zip(keys, values)) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007
participants (4)
-
Andrew Koenig
-
Brian Quinlan
-
George Sakkis
-
Steve Holden