[Tutor] Splitting a string

2011-02-08 Thread tee chwee liong
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'],

Re: [Tutor] Splitting a string

2011-02-08 Thread col speed
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

Re: [Tutor] Splitting a string

2011-02-08 Thread Christian Witts
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

Re: [Tutor] zipfile error message

2011-02-08 Thread Steven D'Aprano
Eric Stevens wrote: Hi: I am relatively new to Python and have been recently trying to experiment with its zipfile capabilities. However, everytime I try to open a zip ( using method zipfile.ZipFile(open('zipfile.zip','r')) ) I continue to get an error message that states:error: unpack requires

Re: [Tutor] Splitting a string

2011-02-08 Thread Steven D'Aprano
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

Re: [Tutor] Splitting a string

2011-02-08 Thread David Hutto
> 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

Re: [Tutor] vim as a python editor

2011-02-08 Thread Paul Griffiths
On 8 February 2011 04:44, Alexander Fairley wrote: > Some high profile ruby hackers have put together a pretty snazzy set of > vim/gvim configs together on github at > > https://github.com/carlhuda/janus > > Thank you, but I think this only works on OSX? I use Ubuntu and if I understand your link

Re: [Tutor] Converting From Unicode to ASCII!!

2011-02-08 Thread Steven D'Aprano
Nevins Duret wrote: A good friend of mine locked herself out of her computer and forgot her password. I pretty much scoured the internet as a resource only to hit a brick wall. I tried using ophcrack version 2.3.1 in order to obtain the password and felt completely at home being that it was

Re: [Tutor] Splitting a string

2011-02-08 Thread tee chwee liong
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

Re: [Tutor] Splitting a string

2011-02-08 Thread David Hutto
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

Re: [Tutor] Splitting a string

2011-02-08 Thread Christian Witts
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

Re: [Tutor] Splitting a string

2011-02-08 Thread David Hutto
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

Re: [Tutor] Splitting a string

2011-02-08 Thread Christian Witts
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

Re: [Tutor] Splitting a string

2011-02-08 Thread Peter Otten
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"

Re: [Tutor] Splitting a string

2011-02-08 Thread Hugo Arts
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

[Tutor] CrackTheInterview

2011-02-08 Thread Polisetti, Vinay
Visit http://www.cracktheinterview.org/ for more interview preparation tips and interview experiences of various people ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] zipfile error message

2011-02-08 Thread Wayne Werner
On Mon, 7 Feb 2011, Eric Stevens wrote: Hi: I am relatively new to Python and have been recently trying to experiment with its zipfile capabilities. However, everytime I try to open a zip ( using method zipfile.ZipFile(open('zipfile.zip','r')) ) I continue to get an error message that states:e

[Tutor] Apologies, mea culpa

2011-02-08 Thread Alan Gauld
Sorry folks, I meant to hit discard on this one but clicked Accept by mistake. Alan G. List moderator ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Splitting a string

2011-02-08 Thread Alan Gauld
"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

Re: [Tutor] Splitting a string

2011-02-08 Thread tee chwee liong
> 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

Re: [Tutor] Splitting a string

2011-02-08 Thread tee chwee liong
> `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

Re: [Tutor] Splitting a string

2011-02-08 Thread Alan Gauld
"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

Re: [Tutor] Splitting a string

2011-02-08 Thread tee chwee liong
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