如何做到Python的拉链在C#中?拉链、Python

2023-09-03 00:09:35 作者:豹纹配蕾丝〃女人的标志

Python的拉链函数执行以下操作:

  A = [1,2,3]
B = [6,7,8]
压缩= ZIP(A,B)
 

结果

 [[1,6],[2,7],[3,8]
 

解决方案

如何this?

C#4.0 LINQ新的ZIP操作符

 公共静态的IEnumerable< TResult>邮编及LT; TFirst,TSecond,TResult>(
        这IEnumerable的< TFirst>第一,
        IEnumerable的< TSecond>第二,
        FUNC< TFirst,TSecond,TResult> FUNC);
 
为什么C 排名和Python相差越来越大

Python's zip function does the following:

a = [1, 2, 3]
b = [6, 7, 8]
zipped = zip(a, b)

result

[[1, 6], [2, 7], [3, 8]]

解决方案

How about this?

C# 4.0 LINQ'S NEW ZIP OPERATOR

public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(
        this IEnumerable<TFirst> first,
        IEnumerable<TSecond> second,
        Func<TFirst, TSecond, TResult> func);