This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: patch for new func. string.findall
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, hfastedge, rhettinger
Priority: normal Keywords: patch

Created on 2003-01-28 02:00 by hfastedge, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
findall.py hfastedge, 2003-01-31 09:30 properly indented version of that which was pasted.
Messages (5)
msg42555 - (view) Author: Hunter Peress (hfastedge) Date: 2003-01-28 02:00
this finds all indices of a substring in a string
returning in list form. Its not in pydoc2.3.

This "patch" contains unittests.

#!/usr/bin/python
import string

def findall(sub,s):
    if s =='' or sub =='':
        return []

    ret=[]
    findval=0
    pos=0
    while findval != -1:
        findval = s.find(sub,pos)
        if findval != -1:
            ret.append(findval)
            pos = findval + len(sub)
    return ret

if __name__ == '__main__':
    units = [
    'asdsad','l',
    'l','asdlsds',
    'l','lsdlsds',
    'l','lsdsds',
    'l','sdsds',
    'l','sdsdsl',
    'l','lsdsdsl',
    'l','lsdlsdsl',

    'l','l',
    'l','ll',
    'l','lll',

    'lo','llollol',
    'lo','llollolo',

    '','',
    '','asdasd',
    'asdsad',''
    ]
    for i in range(0,len(units),2):
        sub,s = units[i],units[i+1]
        print "'%s' in '%s':"%(sub,s)
        print findall(sub,s)
        print "-"*30

    print 'done'
msg42556 - (view) Author: Hunter Peress (hfastedge) Date: 2003-01-28 02:01
Logged In: YES 
user_id=479934

This might be done as an iterator as well, as re.findall
also is complemented by an re.finditer.
msg42557 - (view) Author: Hunter Peress (hfastedge) Date: 2003-01-31 09:31
Logged In: YES 
user_id=479934

Theres now a indented version of that which was pasted above
that is attached to this bug.
msg42558 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-05-29 00:59
Logged In: YES 
user_id=357491

The string module is deprecated so adding anything to the module is a big 
no-no.  If you still want to see this functionality it will require being added to 
the string type.

I am also changing this to a patch since it has working code (albeit as-is it 
would be rejected).
msg42559 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-07-14 07:40
Logged In: YES 
user_id=80475

This function (aspiring method) does not have a strong 
enough use case to warrant fattening the API for str, 
unicode, UserString, etc.

Am closing this one.  But do keep submitting ideas to 
improve the language.
History
Date User Action Args
2022-04-10 16:06:12adminsetgithub: 37849
2003-01-28 02:00:38hfastedgecreate