[Tutor] Customized endswith/startswith version

Alan G alan.gauld at freenet.co.uk
Wed Aug 10 23:54:32 CEST 2005

| >>> [valid for valid in f.readlines() if valid.startswith('abc') or
| valid.startswith('123') or valid.startswith('ff5')]
| how to modify startswith in order to make it accept a list instead 
| a simple string?
| [valid for valid in f.readlines() if valid.startswith(['abc', '123', 

If the strings are all three chars you could do:

[valid for valid in f if valid[:3] in ['abc', '123', 'ff5'] ]


Alan G. 

More information about the Tutor mailing list