
Hi ! A.) The string object have a method named "index", and have a method named "find". It is good, because many times we need to find anything, and it is very long to write this: try: i=s.index('a') except: i=-1 if i<>-1: pass and not this: if (s.find('a')<>-1): pass Why don't exists same method in the list object ? It is very ugly thing (sorry, but I must say that). I must write in every times: l=[1,2,3,4] try: i=l.index(5) except: i=-1 if i<>-1: pass and not this: if (l.find(5)<>-1): pass B.) Same thing is the deleting. I think, this method is missing from strings, and lists. Example: I must write this: s='abcdef' l=[1,2,5,3,4,5] print s s=s[:2]+s[3:] print s print l l[2]=None l.remove(None) print l and not this: s='abcdef' l=[1,2,5,3,4,5] s=s.delete(2) l.delete(2) and delete more: s.delete() # s='' l.delete() # l=[] s.delete(2,2) # s='abef' l.delete(2,2) # l=[1,2,4,5] So: some functions/methods are neeeded to Python-like programming (less write, more effectivity). KK

On Thursday 27 November 2003 11:16 am, Kepes Krisztian wrote: ...
Why don't you use the clearer, faster, more readable, AND more concise idiom if 'a' in s: pass instead?
Why don't exists same method in the list object ?
The 'in' operator works just fine for lists, too. Perhaps if you studied Python's present capabilities a bit better, before requesting changes and additions to Python, you might achieve better results faster.
Same thing is the deleting.
I think, this method is missing from strings, and lists.
Look at the 'del' keyword (and slice assignments) -- for lists only:
del l[2] or equivalently l[2:3] = []
and delete more: s.delete() # s=''
Python strings are immutable and will always remain immutable. There is NO way to change an existing string object and there will never be.
l.delete() # l=[]
l[:] = [] or equivalently del l[:]
s.delete(2,2) # s='abef'
Ditto.
l.delete(2,2) # l=[1,2,4,5]
l[2:4] = [] or equivalently del l[2:4]
So: some functions/methods are neeeded to Python-like programming (less write, more effectivity).
This is quite possible, but I have seen almost none listed in your wishlist. I.e., the only task you've listed that is not performed with easy, popular and widespread Python idioms would seem to be a string method roughly equivalent to the function: def delete(s, from, upto=None): if upto is None: upto = from + 1 return s[:from] + s[upto:] returning "a copy of s except for this slice". However, the addition of more functions and methods that might (perhaps) save typing a few characters, allowing a hypothetical z = s.delete(a, b) in lieu of z = s[:a] + s[b:] must overcome a serious general objection: as your very request shows, people ALREADY fail to notice and learn a lot of what Python offers today. Adding more and more marginally-useful functions and methods might therefore more likely just cause people to fail to notice and learn a larger fraction of Python's capabilities, rather than supply any burningly needed usefulness. Alex

On Thursday 27 November 2003 11:16 am, Kepes Krisztian wrote: ...
Why don't you use the clearer, faster, more readable, AND more concise idiom if 'a' in s: pass instead?
Why don't exists same method in the list object ?
The 'in' operator works just fine for lists, too. Perhaps if you studied Python's present capabilities a bit better, before requesting changes and additions to Python, you might achieve better results faster.
Same thing is the deleting.
I think, this method is missing from strings, and lists.
Look at the 'del' keyword (and slice assignments) -- for lists only:
del l[2] or equivalently l[2:3] = []
and delete more: s.delete() # s=''
Python strings are immutable and will always remain immutable. There is NO way to change an existing string object and there will never be.
l.delete() # l=[]
l[:] = [] or equivalently del l[:]
s.delete(2,2) # s='abef'
Ditto.
l.delete(2,2) # l=[1,2,4,5]
l[2:4] = [] or equivalently del l[2:4]
So: some functions/methods are neeeded to Python-like programming (less write, more effectivity).
This is quite possible, but I have seen almost none listed in your wishlist. I.e., the only task you've listed that is not performed with easy, popular and widespread Python idioms would seem to be a string method roughly equivalent to the function: def delete(s, from, upto=None): if upto is None: upto = from + 1 return s[:from] + s[upto:] returning "a copy of s except for this slice". However, the addition of more functions and methods that might (perhaps) save typing a few characters, allowing a hypothetical z = s.delete(a, b) in lieu of z = s[:a] + s[b:] must overcome a serious general objection: as your very request shows, people ALREADY fail to notice and learn a lot of what Python offers today. Adding more and more marginally-useful functions and methods might therefore more likely just cause people to fail to notice and learn a larger fraction of Python's capabilities, rather than supply any burningly needed usefulness. Alex
participants (2)
-
Alex Martelli
-
Kepes Krisztian