Cho hai chuỗi s và t cùng độ dài. Tạo chuỗi mới bằng cách lấy lần lượt ký tự từ s rồi t: s[0] + t[0] + s[1] + t[1] + ....
Ví dụ: s = "hello", t = "world" → "hweolrllod".
Cách làm
- Dùng
zip(s, t)tạo cặp ký tự tương ứng. - Dùng
maphoặc list comprehension nối từng cặp. ''.join(...)để gộp thành chuỗi hoàn chỉnh.
Ví dụ mã nguồn
def solve(s, t):
zipped = zip(s, t)
zipped = map(lambda x: x[0] + x[1], zipped)
return ''.join(zipped)
s = "hello"
t = "world"
print(solve(s, t)) # hweolrllod
Đầu vào / Đầu ra
Input: "hello", "world"
Output: hweolrllod