본문 바로가기
Data Science/Python

[Python] replace, 합집합/교집합/차집합, 리스트 문자열 합치기

by 로떡 2022. 10. 20.

- replace

line = line.replace('?', '0')

- 합집합 / 교집합 / 차집합 / 대칭차집합

# 합집합
union = list(set(lst1) | set(lst2))

# 교집합
intersection = list(set(lst1) & set(lst2))

# 차집합
complement = list(set(lst1) - set(lst2))

# 대칭차집합
something = list(set(lst1) ^ set(lst2))

- 리스트 문자열로 합치기 (''.join(l))

l = ['d', 'a', 't', 'a']

print(''.join(l)) #data
print('_'.join(l)) #d_a_t_a