파이썬 list 중간 분리
def split_list(keyword, old_list): new_list = [] for item in old_list: if keyword in item: parts = item.split(keyword) new_list.extend([parts[0], keyword, parts[1]]) new_list.remove('') else: new_list.append(item) return new_list before = ['aa', 'bb', 'ccdd', 'eecc', 'ff'] after = split_list('cc', before) print(after) >> ['aa', 'bb', 'cc', 'dd', 'ee', 'cc', 'ff']
2023. 10. 11.