C#相当于旋转使用python切片操作列表 [英] C# equivalent of rotating a list using python slice operation

查看:165
本文介绍了C#相当于旋转使用python切片操作列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中,我可以列表my_list和旋转的内容:

 >>> my_list =列表(范围(10))
>>> my_list
[0,1,2,3,4,5,6,7,8,9]
>>> new_list = my_list [1:] + my_list [:1]
>>> new_list
[1,2,3,4,5,6,7,8,9,0]
 

什么是C#中的等价的方式来创建一个由现有的C#列表的两片一个新的列表?我知道我可以用蛮力如果有必要产生。

解决方案

  VAR newlist = oldlist.Skip(1).Concat(oldlist.Take(1));
 

In python, I can take a list my_list and rotate the contents:

>>> my_list = list(range(10))
>>> my_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> new_list = my_list[1:] + my_list[:1]
>>> new_list
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

What's the equivalent way in C# to create a new list that is a made up of two slices of an existing C# list? I know I can generate by brute force if necessary.

解决方案

var newlist = oldlist.Skip(1).Concat(oldlist.Take(1));

这篇关于C#相当于旋转使用python切片操作列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆