MRAB googlarnett.plus.com wrote:
On Sep 11, 6:11 pm, Fredrik Lundh [EMAIL PROTECTED] wrote:
[snip]
(the next step towards true Pythonicness would be to store your data in
8---
Surely the word is Pythonicity? :-)
When faced with the choice between Pythonicness and
Steven D'Aprano [EMAIL PROTECTED] wrote:
On Thu, 11 Sep 2008 03:36:35 -0500, Nick Craig-Wood wrote:
As an ex-perl programmer and having used python for some years now, I'd
type the explicit
v1,v2,v3 = mydict['one'], mydict['two'], mydict['two'] # 54 chars
Or maybe even
hofer [EMAIL PROTECTED] wrote:
Let's take following perl code snippet:
%myhash=( one = 1, two = 2, three = 3 );
($v1,$v2,$v3) = @myhash{qw(one two two)}; # -- line of interest
print $v1\n$v2\n$v2\n;
How do I translate the second line in a similiar compact way to
python?
One
hofer [EMAIL PROTECTED] wrote:
Let's take following perl code snippet:
%myhash=( one = 1, two = 2, three = 3 );
($v1,$v2,$v3) = @myhash{qw(one two two)}; # -- line of interest
print $v1\n$v2\n$v2\n;
How do I translate the second line in a similiar compact way to
python?
On Thu, 11 Sep 2008 03:36:35 -0500, Nick Craig-Wood wrote:
As an ex-perl programmer and having used python for some years now, I'd
type the explicit
v1,v2,v3 = mydict['one'], mydict['two'], mydict['two'] # 54 chars
Or maybe even
v1 = mydict['one'] # 54 chars
v2 = mydict['two']
Thanks a lot for all your answers.
There's quite some things I learnt :-)
[v1,v2,v3] = ...
can be typed as
v1,v2,v3 = . . .
I also wasn't used to
map(myhash.get, ['one', 'two', 'two'])
itemgetter('one', 'one', 'two')(x)
I also didn't know
print %(one)s\n%(two)s\n%(two)s % mydict
The reason
On Sep 11, 10:36 am, Nick Craig-Wood [EMAIL PROTECTED] wrote:
I'd type the explicit
v1,v2,v3 = mydict['one'], mydict['two'], mydict['two'] # 54 chars Either
is only a couple more
characters to type. It is completely
explicit and comprehensible to everyone, in comparison to
v1,v2,v3 =
hofer:
The real example would be more like:
name,age,country = itemgetter('name age country'.split())(x) # or any
of my above versions
That solution is very clever, and the inventor smart, but it's too
much out of standard and complex to be used in normal real code.
Learning tricks is useful,
hofer wrote:
The real example would be more like:
name,age,country = itemgetter('name age country'.split())(x)
ouch.
if you do this a lot (=more than once), just wrap your dictionaries in a
simple attribute proxy, and use plain attribute access. that is, given
class
On Sep 11, 10:52 am, hofer [EMAIL PROTECTED] wrote:
On Sep 11, 10:36 am, Nick Craig-Wood [EMAIL PROTECTED] wrote:
I'd type the explicit
v1,v2,v3 = mydict['one'], mydict['two'], mydict['two'] # 54 chars Either
is only a couple more
characters to type. It is completely
explicit and
On Sep 11, 6:11 pm, Fredrik Lundh [EMAIL PROTECTED] wrote:
[snip]
(the next step towards true Pythonicness would be to store your data in
class instances instead of dictionaries in the first place, but one step
at a time...)
Surely the word is Pythonicity? :-)
--
Hi,
Let's take following perl code snippet:
%myhash=( one = 1, two = 2, three = 3 );
($v1,$v2,$v3) = @myhash{qw(one two two)}; # -- line of interest
print $v1\n$v2\n$v2\n;
How do I translate the second line in a similiar compact way to
python?
Below is what I tried. I'm just
On Wed, 10 Sep 2008 08:28:43 -0700 (PDT), hofer wrote:
Hi,
Let's take following perl code snippet:
%myhash=( one = 1, two = 2, three = 3 );
($v1,$v2,$v3) = @myhash{qw(one two two)}; # -- line of interest
print $v1\n$v2\n$v2\n;
What about:
myhash={'one':1, 'two':2, 'three':3}
On 10 Sep, 16:28, hofer [EMAIL PROTECTED] wrote:
Hi,
Let's take following perl code snippet:
%myhash=( one = 1 , two = 2 , three = 3 );
($v1,$v2,$v3) = @myhash{qw(one two two)}; # -- line of interest
print $v1\n$v2\n$v2\n;
How do I translate the second line in a similiar compact
for a long list, you could try:
result = [mydict[k] for k in mydict]
or [mydict[k] for k in mydict.keys()]
or [mydict[k] for k in mydict.iterkeys()]
this won't give you the same order as your code though, if you want them
sorted you can use the sorted function:
[mydict[k]
B wrote:
for a long list, you could try:
result = [mydict[k] for k in mydict]
or [mydict[k] for k in mydict.keys()]
or [mydict[k] for k in mydict.iterkeys()]
and the point of doing that instead of calling mydict.values() is what?
/F
--
Fredrik Lundh wrote:
B wrote:
for a long list, you could try:
result = [mydict[k] for k in mydict]
or [mydict[k] for k in mydict.keys()]
or [mydict[k] for k in mydict.iterkeys()]
and the point of doing that instead of calling mydict.values() is what?
/F
It's more fun? Or if
hofer wrote:
Let's take following perl code snippet:
%myhash=( one = 1, two = 2, three = 3 );
($v1,$v2,$v3) = @myhash{qw(one two two)}; # -- line of interest
print $v1\n$v2\n$v2\n;
How do I translate the second line in a similiar compact way to
python?
Below is what I tried. I'm
18 matches
Mail list logo