SQL / Python - String replacement pattern with commas -


i need achieve following task using preferably sql string functions (i.e charindex, left, trim, etc) or python.

here's problem:

example string: bob 3a, alice 6m  required output: 3ab, 6ma 

as can see need last 2 characters each word preceding comma, append first character of each item end. preferably should work number of items commas separating them case two.

any hints / direction great. thanks.

here's python solution:

def thesplit(s):     result = []      each in s.split(', '):         name, chars = each.split(' ')         result.append(chars.lower() + name[0])      return ', '.join(result) 

you can use this: thesplit('bob 3a, alice 6m')


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -