"tee chwee liong" wrote
t> hanks for catching the bug. the code should be:
s='11100101'
found = False
for i,c in enumerate(reversed(s)):
if c == '0':
print 'Lane fail',i
found = True
if not found: print 'All lanes PASS'
the if not found needs to be indented.
No, e
> No, it doesn't work. You haven't sufficiently tested it. It tells lies:
>
>
> >>> s='11100101'
> >>> found = False
> >>> for i,c in enumerate(s):
> ... if c == '0':
> ... print 'Lane fail',i
> ... found = True
> ... if not found: print 'All lanes PASS'
> ...
> All lanes PASS
> All lanes PASS
>
tee chwee liong wrote:
hi all,
the code works:
s='00101'
found = False
for i,c in enumerate(s):
if c == '0':
print 'Lane fail',i
found = True
if not found: print 'All lanes PASS
No, it doesn't work. You haven't sufficiently tested it. It tells lies:
>>> s='111
>s='00101'
>found = False
>for i,c in enumerate(s):
>if c == '0':
>print 'Lane fail',i
>found = True
>if not found: print 'All lanes PASS
>#
>
>the enumerate is checking from left to right. is it possible check from right
>to
>left?
>
>for eg:s='00101'
>The ea
hi all,
the code works:
s='00101'
found = False
for i,c in enumerate(s):
if c == '0':
print 'Lane fail',i
found = True
if not found: print 'All lanes PASS
#
Result:
>>>
Lane fail 0
Lane fail 1
Lane fail 3
>>>
the enumerate is checking from left to right. is
"tee chwee liong" wrote
###
c=('01101')
i=-1
try:
while i print "Lane fail",i
except ValueError:
print "All Lanes PASS"
pass
#
The first thing is that you never increment i so the
while condition is never going to terminate, so its
probably just
> `while i < len(c)` instead of `while 1`
>
hi,
i modified codes to be i>>
Lane fail 0
Lane fail 3
All Lanes PASS
>>>
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options
> I'm not sure what you mean by highlight the location.
> Is it a GUI? Are you colour coding the characters?
>
hi,
no it is not GUI. i just want to know where is the location of the 0 in the
returned string. For eg: 10111, i want to say 0 is at lane 3 (calculating
location from right to le
"tee chwee liong" wrote
i have a function which returns a string. for eg: X='101110'.
i want to search for 0 and highlight the location.
I'm not sure what you mean by highlight the location.
Is it a GUI? Are you colour coding the characters?
i am thinking of defining X as a list.
You
On Tue, Feb 8, 2011 at 2:47 PM, Christian Witts
>>> `while i< len(c)` instead of `while 1`
>>>
>>
>> You remind me of me...like it was yesterday. Explanations with no
>> thought. Unimpressive isn't it?
>>
>
> While the index is smaller than the length of the string do your processing.
> It reads
Christian Witts wrote:
> On 08/02/2011 15:04, tee chwee liong wrote:
>> hi all,
>>
>> thanks for the advice. i modified my code to be:
>>
>> c=('01101')
>> i=-1
>> try:
>> while 1:
>> i=c.index('0',i+1)
>> print "Lane fail",i
>> except ValueError:
>> print "All Lanes PASS"
On 08/02/2011 15:38, David Hutto wrote:
On Tue, Feb 8, 2011 at 8:36 AM, Christian Witts wrote:
On 08/02/2011 15:04, tee chwee liong wrote:
hi all,
thanks for the advice. i modified my code to be:
c=('01101')
i=-1
try:
while 1:
i=c.index('0',i+1)
print "Lane fail
On Tue, Feb 8, 2011 at 8:36 AM, Christian Witts wrote:
> On 08/02/2011 15:04, tee chwee liong wrote:
>>
>> hi all,
>>
>> thanks for the advice. i modified my code to be:
>>
>> c=('01101')
>> i=-1
>> try:
>> while 1:
>> i=c.index('0',i+1)
>> print "Lane fail",i
>> except ValueError
On 08/02/2011 15:04, tee chwee liong wrote:
hi all,
thanks for the advice. i modified my code to be:
c=('01101')
i=-1
try:
while 1:
i=c.index('0',i+1)
print "Lane fail",i
except ValueError:
print "All Lanes PASS"
pass
when i run, the result is:
>>>
Lane fail 0
Lane
Don't use the try and except, use a if else. I'm not as good as an
explainer as the pros, but I can make enough sense if you respond back
with a useful set of examples you've tried.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscrip
hi all,
thanks for the advice. i modified my code to be:
c=('01101')
i=-1
try:
while 1:
i=c.index('0',i+1)
print "Lane fail",i
except ValueError:
print "All Lanes PASS"
pass
when i run, the result is:
>>>
Lane fail 0
Lane fail 3
All Lanes PASS
Qu
> To get a list, just ask for one:
>
list("abcd")
> ['a', 'b', 'c', 'd']
>
or., and this isn't to argue with anyone;), you could:
>>> x = 'abcd'
>>> y = []
>>> for letter in x:
... y.append(letter)
...
>>> print y
['a', 'b', 'c', 'd']
which explains that the list is derived from the st
tee chwee liong wrote:
hi all,
i have a function which returns a string. for eg: X='101110'. i want
to search for 0 and highlight the location. i am thinking of defining
X as a list. but how can i split 101110 as there are no spaces in
between? i'm thinking if i can put it into a list:
X=['1','0
On 08/02/2011 11:20, tee chwee liong wrote:
hi all,
i have a function which returns a string. for eg: X='101110'. i want
to search for 0 and highlight the location.
i am thinking of defining X as a list. but how can i split 101110 as
there are no spaces in between? i'm thinking if i can put it
On 8 February 2011 16:20, tee chwee liong wrote:
> hi all,
>
> >i have a function which returns a string. for eg: X='101110'. i want to
> search for 0 and highlight the location.
> i> am thinking of defining X as a list. but how can i split 101110 as there
> are no spaces in between? i'm thinkin
hi all,
i have a function which returns a string. for eg: X='101110'. i want to search
for 0 and highlight the location.
i am thinking of defining X as a list. but how can i split 101110 as there are
no spaces in between? i'm thinking if i can put it into a list:
X=['1','0','1','1','1','0'],
Steve Nelson wrote:
> Indeed - as I now have a function:
>
> def nsplit(s, n):
> return [s[i:i+n] for i in range(0, len(s), n)]
>
> Incidentally I am currently going with:
>
> def nsplit(s, n):
> while s:
>yield s[:n]
>s = s[n:]
You can write the generator function to use the same m
On 3/14/06, Adam <[EMAIL PROTECTED]> wrote:
> Hopefully that should point you in the right direction to do n-sized
> words as well.
Indeed - as I now have a function:
def nsplit(s, n):
return [s[i:i+n] for i in range(0, len(s), n)]
Incidentally I am currently going with:
def nsplit(s, n):
| From: "Steve Nelson"
|
| Further to my previous puzzling, I've been working out the best way to
| chop a string up into n-sized words:
|
I think the follow use of groupby is from Raymond Hettinger from ASPN recipes.
The batch() function will return an iterable to you in user-definable sized
On 14/03/06, Steve Nelson <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> Further to my previous puzzling, I've been working out the best way to
> chop a string up into n-sized words:
>
> I'm aware that I can use a slice of the string, with, eg, myWord[0:4].
>
> I am also aware that I can do blob = myW
Hello all,
Further to my previous puzzling, I've been working out the best way to
chop a string up into n-sized words:
I'm aware that I can use a slice of the string, with, eg, myWord[0:4].
I am also aware that I can do blob = myWord.pop(0) to take (and
remove) the first character. I can botch
26 matches
Mail list logo