-1

1708:com.google.android.partnersetup/u0a120 this is line

I want output as : ['1708','com','google','android','partnersetup','u0a120']

I tried this

result_1 = [item.split(':')[0] for item in listli[8]]
print(result_1)

but it giving me the output : ['1', '7', '0', '8', '', 'c', 'o', 'm', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'a', 'n', 'd', 'r', 'o', 'i', 'd', '.', 'p', 'a', 'r', 't', 'n', 'e', 'r', 's', 'e', 't', 'u', 'p', '/', 'u', '0', 'a', '1', '2', '0']

can u plz help me to get me the output I want ?

2 Answers2

0

You can use re.split.

import re
pattern = r'[:.//]'
s = '1708:com.google.android.partnersetup/u0a120'
print(re.split(pattern, s))

Result:

['1708', 'com', 'google', 'android', 'partnersetup', 'u0a120']

Taken from this answer: Python 3: Split string under certain condition

by Jim Wright

0
import re
result_1 = re.split('[:/ .]+', '1708:com.google.android.partnersetup/u0a120')
print(result_1)
['1708', 'com', 'google', 'android', 'partnersetup', 'u0a120']

LegendWK
  • 184
  • 9
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Dec 06 '22 at 09:48