Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
pythonic way
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
MRAB  
View profile  
 More options Nov 1 2012, 11:52 am
Newsgroups: comp.lang.python
From: MRAB <pyt...@mrabarnett.plus.com>
Date: Thu, 01 Nov 2012 15:52:11 +0000
Local: Thurs, Nov 1 2012 11:52 am
Subject: Re: pythonic way
On 2012-11-01 15:32, inshu chauhan wrote:
>   what is the most pythonic way to do this :

>                     if 0 < ix < 10 and 0 < iy < 10 ???

That looks Pythonic to me, except for the missing colon.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Chase  
View profile  
 More options Nov 1 2012, 11:56 am
Newsgroups: comp.lang.python
From: Tim Chase <python.l...@tim.thechases.com>
Date: Thu, 01 Nov 2012 10:57:12 -0500
Local: Thurs, Nov 1 2012 11:57 am
Subject: Re: pythonic way
On 11/01/12 10:32, inshu chauhan wrote:

>  what is the most pythonic way to do this :

>                    if 0 < ix < 10 and 0 < iy < 10 ???

What's wrong with the syntax you provide?  It's perfectly pythonic:

  ix = 42
  yx = 3.14159
  if 0 < ix < 10 and 0 < iy < 10:
    do_stuff(ix, iy)
  else:
    do_other_stuff(ix, iy)

-tkc


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Terry Reedy  
View profile  
 More options Nov 1 2012, 12:05 pm
Newsgroups: comp.lang.python
From: Terry Reedy <tjre...@udel.edu>
Date: Thu, 01 Nov 2012 12:04:12 -0400
Local: Thurs, Nov 1 2012 12:04 pm
Subject: Re: pythonic way
On 11/1/2012 11:32 AM, inshu chauhan wrote:

>   what is the most pythonic way to do this :

>                     if 0 < ix < 10 and 0 < iy < 10 ???

end with : instead of ???

 >>> ix, iy = 3,4
 >>> if 0 < ix < 10 and 0 < iy < 10:
        print('This was too easy')

This was too easy

--
Terry Jan Reedy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zero Piraeus  
View profile  
 More options Nov 1 2012, 12:55 pm
Newsgroups: comp.lang.python
From: Zero Piraeus <sche...@gmail.com>
Date: Thu, 1 Nov 2012 12:54:43 -0400
Local: Thurs, Nov 1 2012 12:54 pm
Subject: Re: pythonic way
:

On 1 November 2012 11:32, inshu chauhan <insidesh...@gmail.com> wrote:

>  what is the most pythonic way to do this :

>                    if 0 < ix < 10 and 0 < iy < 10 ???

As everyone else has said, it's perfectly pythonic once you stick the
colon on the end. You might find it more instantly readable with some
extra parentheses:

    if (0 < ix < 10) and (0 < iy < 10):
        # do something

... but that's really just down to taste.

 -[]z.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jack  
View profile  
 More options Nov 2 2012, 3:15 am
Newsgroups: comp.lang.python
From: jack <naruto...@live.cn>
Date: Fri, 2 Nov 2012 15:14:32 +0800
Local: Fri, Nov 2 2012 3:14 am
Subject: Re: pythonic way
Sometimes, I need to alter the element as traverse a list like this
(it's a sample):
     c = range(10)
     i = 0
     for ele in c:
         # do something
         # branch:
             c[i] = # value
         i += 1

How to be pythonic?

  2012/11/2 0:54, Zero Piraeus :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Nov 2 2012, 3:56 am
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Fri, 2 Nov 2012 18:56:33 +1100
Local: Fri, Nov 2 2012 3:56 am
Subject: Re: pythonic way

On Fri, Nov 2, 2012 at 6:14 PM, jack <naruto...@live.cn> wrote:
> Sometimes, I need to alter the element as traverse a list like this (it's a
> sample):
>     c = range(10)
>     i = 0
>     for ele in c:
>         # do something
>         # branch:
>             c[i] = # value
>         i += 1

> How to be pythonic?

Check out the enumerate() function.

ChrisA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jack  
View profile  
 More options Nov 2 2012, 4:59 am
Newsgroups: comp.lang.python
From: jack <naruto...@live.cn>
Date: Fri, 2 Nov 2012 16:58:17 +0800
Local: Fri, Nov 2 2012 4:58 am
Subject: Re: pythonic way
thanks,but I don't think enumerate() is my want
Have some ways to operate the reference of element,not a copy when I
tried to traverse a list?

I'm so sorry about my poor English, hope you don't mind it.

On 2012/11/2 15:56, Chris Angelico wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Nov 2 2012, 5:11 am
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Fri, 2 Nov 2012 20:11:49 +1100
Local: Fri, Nov 2 2012 5:11 am
Subject: Re: pythonic way

On Fri, Nov 2, 2012 at 7:58 PM, jack <naruto...@live.cn> wrote:
> thanks,but I don't think enumerate() is my want
> Have some ways to operate the reference of element,not a copy when I tried
> to traverse a list?

> I'm so sorry about my poor English, hope you don't mind it.

No probs, I'll be a little less vague and pointer-y and give you some
example code. :)

lst = ['foo', 'bar', 'quux', 'asdf', 'qwer', 'zxcv']
for idx, val in enumerate(lst):
    if val[1]=='w': lst[idx]='Replaced'
print(lst)

['foo', 'bar', 'quux', 'asdf', 'Replaced', 'zxcv']

Does that explain it a bit better? You get the index and can then
mutate the list using that index, thus replacing the original entry.

ChrisA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »