111

I want to parse something like:

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

And using list slicing have it return to me everything but the first index:

['B', 'C']

I tried list[:-1], list[::-1], list[0:-1], etc.

What I am doing:

  • I have a error message that has an error code in the beginning such as:

    ['226', 'Transfer', 'Complete'] and I want to just display Transfer Complete on a popup widget. I am casting to a string.

If answer differs via Python 2.7.x and Python 3.x.x, please answer for both versions.

7
  • 16
    You want to start at the second element, so use list[1:]. Commented Nov 5, 2016 at 21:21
  • 4
    Don't you need [1:] ? Commented Nov 5, 2016 at 21:21
  • 3
    " ".join(lst[1:]) to make Transfer complete Commented Nov 5, 2016 at 21:23
  • @cricket_007 is that an alternative of doing .split( " ") [1:]? Commented Nov 5, 2016 at 21:25
  • Split returns a list. Slicing returns a list. String Joining returns a string, so no, it's the inverse, not alternative Commented Nov 5, 2016 at 21:29

2 Answers 2

178

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

Sign up to request clarification or add additional context in comments.

Comments

61

It can be done like this:

list[1:]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.