Monday, 15 June 2015

python - Ruby remove words ending with '.' -



python - Ruby remove words ending with '.' -

i'm looking remove middle initials in series of names. found out python figured seek inrruby. in python utilize endswith command remove of middle initials in csv file because items ended in '.'

example

steve a. walkins michael todd angel, blair c.

not names follow set pattern, middle initials do. teach myself ruby trying find out equivilent command , usage endswith function in python.

my sample python code worked was.

print ' '.join(i in name.split(' ') if not i.endswith('.'))

not pretend reply improve 1 suggested ivaylo strandjev, in case want oneliner ‘translation’ of python code ruby:

name.split.select{|t| !t.end_with?('.')}.join(' ')

or, clearer (thanks @Ɓukaszniemier)

name.split.reject{|t| t.end_with?('.')}.join(' ')

python ruby

No comments:

Post a Comment