colab Open in SageMaker Studio Lab Open in Planetary Computer

Overloaded Operators for the ee.List Object Class

Tutorial created by **David Montero Loaiza**: GitHub | Twitter

Let’s start!

If required, please uncomment:

[1]:
#!pip install eemont
#!pip install geemap

Import the required packages.

[2]:
import ee, eemont, geemap

Authenticate and Initialize Earth Engine and geemap.

[3]:
Map = geemap.Map()

Let’s define some ee.List objects:

[4]:
L1 = ee.List.sequence(0,4)
L2 = ee.List.sequence(5,9)

Overloaded Operators

eemont has overloaded the binary operators in the following list for the ee.List class:

(+, *)

Therefore, you can now use them for list operations!

Concatenation

Concatenate two or more ee.List objects using the + Overloaded Operator:

[5]:
L3 = L1 + L2

The result is stored as an ee.List class. Let’s check it:

[6]:
L3.getInfo()
[6]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Repeat

Repeat a list n times using the * Overloaded Operator:

[7]:
L4 = ee.List([10]) * 5

Check the result:

[8]:
L4.getInfo()
[8]:
[10, 10, 10, 10, 10]

Here is another example:

[9]:
L5 = L3 * 2

Check the result:

[10]:
L5.getInfo()
[10]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]