Python
- 2 ответа
- 0 вопросов
1
Вклад в тег
teststr = 'elemen1:12345;element2:54321;element3:6789'
result_list = teststr.replace(':', ';').split(';')
print('Result:', result_list)
Result: ['elemen1', '12345', 'element2', '54321', 'element3', '6789']
import re
teststr = 'elemen1:12345;element2:54321;element3:6789'
result_list = re.split('[;:]', teststr)
print('Result:', result_list)
Result: ['elemen1', '12345', 'element2', '54321', 'element3', '6789']
teststr = 'elemen1:12345;element2:54321;element3:6789'
result_list = [elem for elem in teststr.replace(':', ';').split(';') if elem.isdigit()]
print(result_list)
["['Первое", "'Второе'", "'Третье'", "'Четвертое']"]
string = "['Первое, 'Второе', 'Третье', 'Четвертое']"
res = [element.strip("'[]") for element in string.split(", ")]
print(res[1])
Второе