hobo takes the wheel
hobo takes the wheel

Reputation: 131

How do I pop() elements inside the list in python2.7

I just want to ask if how should I pop certain elements inside the list.

Let's say I have this list:

c = ['123','456','789']

When I type this:

print c[0][0]

It prints a value '1',

And somehow I want to delete the first element of the first value.

So that the output will be:

c = ['23','456','789']

But I have a problem in using pop().

I tried this but no luck:

c.pop(0, 0) # takes only one argument

Or

c[0].pop(0) # string doesn't have an attribute pop

Is there a way to solve my dilemma?

If this problem has a duplicate, please let me know.

Upvotes: 0

Views: 336

Answers (1)

DeepSpace
DeepSpace

Reputation: 81594

Strings are immutable. As such, they can't be modified once created.

If all you want to do is "remove" the first character of the first string in the list c you can use slicing (that returns a new string):

c[0] = c[0][1:]

Read more on slicing here: Explain Python's slice notation

Upvotes: 3

Related Questions