0

We have this list:

lista = ['int32',
 'decimal(14)',
 'int(32)',
 'string',
 'date',
 'decimal(27,2)',
 'decimal(17,2)']

And we need:

['int32', 'decimal', '(14)',
 'int', '(32)',
 'string',
 'date',
 'decimal','(27,2)',
 'decimal','(17,2)']

We use

for i in lista:
    .split('(')

but we lose ( in the process.

quamrana
  • 37,849
  • 12
  • 53
  • 71
Idoia Pico
  • 25
  • 1
  • 6
  • 1
    But since you know that `'('` has been removed you can easily add it back. – quamrana Feb 23 '22 at 11:24
  • See https://stackoverflow.com/questions/2136556/in-python-how-do-i-split-a-string-and-keep-the-separators?noredirect=1&lq=1 – MarcelH Feb 23 '22 at 11:25

1 Answers1

0

works this code :)

lista = ['int32','decimal(14)','int(32)','string','date','decimal(27,2)','decimal(17,2)']
lst = []
for i in lista:
    x= (i.find('('))
    if(x != -1):
        lst.append(i[0:x])
        lst.append(i[x::])
    else:
        lst.append(i)
print(lst)