Python Forum
How to use Del with list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use Del with list
#11
It makes it very difficult to copy your code and run it.
What IDE are you using?
Reply
#12
I'm really struggling to understand what your objective is as you've been given two approaches to removing the first and last elements:
  • use slicing, list[1:-1]
  • use del: del list[0]; del list[-1]
You talking about checking len, but len does not need checking.

If you are wanting to do something different to what you've already described, where you need to keep track of elements in a list whilst deleting, there are two common approaches:
  • create a new list containing what you want
  • delete from the end, and go backwards (which avoids things changing position)
I am trying to help you, really, even if it doesn't always seem that way
Reply
#13
(Sep-21-2018, 12:17 AM)Larz60+ Wrote: It makes it very difficult to copy your code and run it.
What IDE are you using?

VIM with Syntastic and some other plugins. Maybe there is an export code option somewhere that removes the line numbers and markups. That is why I initially posted to hastebin. That and pastebin people have been using for years. Makes it really easy to copy and paste.

Thank you all for your responses. Really appreciate the help.
Reply
#14
you can also use something like VSCode then it's as simple as highlight, ctrl-C, ctrl-V
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020