
April 27th, 2001, 03:11 AM
|
|
Contributing User
|
|
Join Date: Jul 2000
Posts: 58

Time spent in forums: < 1 sec
Reputation Power: 8
|
|
PHP Code:
import string
def specialsplit(str, split):
str2list = string.split(str,split)
nlist=[]
for item in str2list:
if item == str2list[-1]:# skip last
nlist.append(item)
else:
nlist = nlist+[item,split]
return nlist
print specialsplit("peter@bengtsson","@")
# returns ['peter', '@', 'bengtsson']
-------------------
Is there a better way to do this? A Builtin or something perhaps.
|