[EMAIL PROTECTED] wrote: (please, *stop* top-posting - corrected) > Bruno Desthuilliers wrote: >> >> [EMAIL PROTECTED] wrote: >> (OT : please dont top-post) >> >>> What I tried to do is to write a string.split() module, >> So don't waste time: >> >>>>> "ab eced f aazaz".split() >> ['ab', 'eced', 'f', 'aazaz'] >>>>> "ab-eced-ff-aazaz".split('-') >> ['ab', 'eced', 'ff', 'aazaz'] >> > Thank you for your reminder:) > > However I saw the split() function in the first place and that why I'm > trying write one myself:)
Ok. Then if it's for learning, let's have a look :) > def spilt(a): def split(astring, sep=' '): > l=[] > index=0 > if not isinstance(a, basestring): #Or isinstance(a, str) > return It's an error, so you don't want to pass it silently: if not isinstance(astring, basetring): raise TypeError('expected a string or unicode, got : %s' \ % type(astring) > for i in len(a): The common idiom is : "for item in sequence:". If you need indexes too, use enumerate: "for i, char in enumerate(astring):". But anyway, you may want to have a look at str.find() or str.index(). > if a[i]=' ': > item=a[index:i] > l.append(item) Good luck... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list