screeps-starter-python
1.0.0
1.0.0
  • Introduction
  • Logistics
    • Setup
    • Upgrading Transcrypt
  • Screeps API Usage
    • Constants
    • Optional Arguments
    • Objects - Basic Interaction
    • Objects - Creation and the Keyword "new"
  • Features
    • Console Commands
  • Lodash
    • Introduction
    • As Arguments to API Methods
  • Syntax Changes
    • Summary
    • in Opperator
    • List Behavior
    • del Operator
    • dict Iteration
Powered by GitBook
On this page

Was this helpful?

  1. Syntax Changes

del Operator

PreviousList BehaviorNextdict Iteration

Last updated 4 years ago

Was this helpful?

In python, del list[0] will delete the first item in the list, and truncate it.

The same is not true in Transcrypt. Transcrypt translates del directly to JavaScript's delete, so you'll end up with an incoheret list if you use this operator.

Instead, using the pop operator can work.

# in regular python:
del list[0]
# in Screeps via Transcrypt:
list.pop(0)

If you need to delete a range, the JavaScript method can help:

# in regular python:
del list[1:3] # delete items 1 through 3, exclusive
# in Screeps via Transcrypt:
list.splice(1, 2) # delete 2 items, starting with index 1
splice