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
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
> 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
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
> 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.
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)