如何使用列表切片从列表中获取除第一个元素以外的所有内容 [英] How to get everything from the list except the first element using list slicing

查看:689
本文介绍了如何使用列表切片从列表中获取除第一个元素以外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我要解析一些内容,但是下面是我想做的一个例子:

list = ['A', 'B', 'C']

然后使用列表切片将除第一个索引之外的所有内容都返回给我.因此,在这种情况下:

['B', 'C']

我一直在弄乱诸如list [:-1],list [::-1],list [0:-1]之类的东西,但是我似乎无法找到答案. /p>

我实际正在做的是: *我有一条错误消息,开头有错误代码,例如:

['226', 'Transfer', 'Complete']

,我只想在弹出窗口小部件上显示传输完成".当然,我要转换为字符串.

感谢您提供的所有帮助,如果Python 2.7.x和Python 3.x.x的答案有所不同,请同时回答这两个版本.

谢谢,在stackoverflow上看了很多,而python教程并不能真正得到我想要的东西.感谢您的帮助!

解决方案

您可以执行[1:]. 这将在两个版本上都适用.

So I have something that I am parsing, however here is an example of what I would like to do:

list = ['A', 'B', 'C']

And using list slicing have it return to me everything but the first index. So in this case:

['B', 'C']

I have been messing with stuff like list[:-1], list[::-1], list[0:-1], etc. But I can't seem to be able to find this out.

What I am actual doing is: * I have a error message that has a error code in the beginning such as:

['226', 'Transfer', 'Complete']

and I want to just display Transfer Complete on a popup widget. Of course I am casting to a string.

Thank you for all help, and if answer differs via Python 2.7.x and Python 3.x.x Please answer for both versions.

Thanks, looked a lot around stackoverflow and python tutorials couldn't really quite get what I was looking for. Thanks for your help!

解决方案

You can just do [1:]. This will work on both versions.

这篇关于如何使用列表切片从列表中获取除第一个元素以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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