Zip

🟢 VB.NET
投稿日: 2026年4月18日14:07
Dim numbers = New List(Of Integer) From {1, 2, 3, 4}
        Dim words = New List(Of String) From {"one", "two", "three", "foure"}
        Dim numbersAndWords As Dictionary(Of Integer, String)
        numbersAndWords = numbers.Zip(words,
            Function(k, v) New With {k, v}).ToDictionary(
                Function(anony) anony.k,
                Function(anony) anony.v
        )

        For Each item In numbersAndWords
            Console.WriteLine("{0}_{1}", item.Key, item.Value)
        Next
シーケンスをマージ

1_one
2_two
3_three
4_foure

Python
# 例1: 2つのリストを結合してペアを作成する
numbers = [1, 2, 3, 4, 5]
letters = ['A', 'B', 'C', 'D', 'E']

combined = zip(numbers, letters)
print(list(combined))
# [(1, 'A'), (2, 'B'), (3, 'C'), (4, 'D'), (5, 'E')]