Runtime v2.81 · Updated Sep 30, 2026

set

A mutable collection of unique values.

Syntax

set(iterable=None, /)

Parameters

None

Returns

set

Behavior / side effects

A mutable collection of unique values. CogniTab keeps iteration order stable so script output is easy to read.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = {1, 2, 2}
seen.add(3)

if 2 in seen:
    text(str(seen))

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

None

Methods

17 methods

set.constructor

Create an empty set or collect unique values from another iterable, including a generator expression.

Syntax

set()
set(iterable, /)

Parameters

NameDescription
iterableIterable
Optional source values to deduplicate into the new set.
Depends on overload · Positional only
Default: None

Returns

set — A new mutable set.

Behavior / side effects

Create an empty set or collect unique values from another iterable, including a generator expression.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = set()
unique = set([1, 2, 2, 3])

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.literal

Create a set literal inline.

Syntax

{1, 2, 3}

Parameters

NameDescription
valueAny?
Each value written inside the braces.
Required · Positional or named
No default

Returns

set — A new mutable set that keeps one copy of each value.

Behavior / side effects

Create a set literal inline. Use dict() or {} for an empty dictionary; use set() for an empty set.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

unique = {1, 2, 2, 3}
text(str(unique))        # returns {1, 2, 3}

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.comprehension

Build a set by looping through an iterable and keeping unique calculated values.

Syntax

{expr for target in iterable if condition}

Parameters

NameDescription
exprAny?
Value calculated for each accepted item.
Required · Positional or named
No default
targetName | destructuring target
Loop target for the current item. Starred targets are not supported.
Required · Positional or named
No default
iterableIterable
Source values to loop through.
Required · Positional or named
No default
conditionBoolean
Optional filter checked before adding a value.
Optional · Positional only
Default: True

Returns

set — A new mutable set.

Behavior / side effects

Build a set by looping through an iterable and keeping unique calculated values. Multiple for/if clauses are supported.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

values = [1, 2, 3, 4, 5]
remainders = {x % 3 for x in values}

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.length

Count how many unique values are in the set.

Syntax

len(set, /)

Parameters

NameDescription
setset
The set to count.
Required · Positional only
No default

Returns

Int — Number of set values.

Behavior / side effects

Count how many unique values are in the set.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

values = {1, 2, 2}
count = len(values)      # returns 2

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.membership_operator

Check whether a value exists in the set.

Syntax

value in set

Parameters

NameDescription
valueAny?
Value to test.
Required · Positional or named
No default
setset
Set used for membership.
Required · Positional or named
No default

Returns

Boolean — true when the value exists, otherwise false.

Behavior / side effects

Check whether a value exists in the set.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

values = {1, 2, 3}
if 2 in values:
    text("ready")

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.add_method

Add one value to the set.

Syntax

set.add(value, /)

Parameters

NameDescription
valueAny?
Value to add.
Required · Positional only
No default

Returns

None — No direct return value. The set is updated in place.

Behavior / side effects

Add one value to the set. Existing values are kept once.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = set()
seen.add("home")

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.discard_method

Remove a value if it exists.

Syntax

set.discard(value, /)

Parameters

NameDescription
valueAny?
Value to remove if present.
Required · Positional only
No default

Returns

None — No direct return value. The set may be updated in place.

Behavior / side effects

Remove a value if it exists. Missing values are ignored.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = {"home", "shop"}
seen.discard("shop")

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.remove_method

Remove an existing value.

Syntax

set.remove(value, /)

Parameters

NameDescription
valueAny?
Value that must exist in the set.
Required · Positional only
No default

Returns

None — No direct return value. The set is updated in place.

Behavior / side effects

Remove an existing value. Missing values raise a runtime error so mistakes are visible.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = {"home", "shop"}
seen.remove("home")

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.pop_method

Remove and return one value from the set.

Syntax

set.pop()

Parameters

None

Returns

Any? — Removed value.

Behavior / side effects

Remove and return one value from the set. Empty sets raise a runtime error.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = {"home", "shop"}
value = seen.pop()

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.update_method

Add values from one or more iterables into the set.

Syntax

set.update(*iterables)

Parameters

NameDescription
iterablesIterable
Sources to add.
Optional · Variadic
No default

Returns

None — No direct return value. The set is updated in place.

Behavior / side effects

Add values from one or more iterables into the set.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = {"home"}
seen.update(["shop", "home"])

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.union_method

Return a new set with values from this set and the provided iterables.

Syntax

set.union(*iterables)

Parameters

NameDescription
iterablesIterable
Sources to merge.
Optional · Variadic
No default

Returns

set — Merged set copy.

Behavior / side effects

Return a new set with values from this set and the provided iterables.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

a = {"home"}
b = a.union(["shop"])

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.intersection_method

Return a new set containing values that also exist in every provided iterable.

Syntax

set.intersection(*iterables)

Parameters

NameDescription
iterablesIterable
Sources to compare.
Optional · Variadic
No default

Returns

set — Intersection set copy.

Behavior / side effects

Return a new set containing values that also exist in every provided iterable.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

a = {"home", "shop"}
b = a.intersection(["shop"])

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.difference_method

Return a new set without values found in the provided iterables.

Syntax

set.difference(*iterables)

Parameters

NameDescription
iterablesIterable
Sources to subtract.
Optional · Variadic
No default

Returns

set — Difference set copy.

Behavior / side effects

Return a new set without values found in the provided iterables.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

a = {"home", "shop"}
b = a.difference(["home"])

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.copy_method

Copy the set into a new mutable set.

Syntax

set.copy()

Parameters

None

Returns

set — A new set with the same values.

Behavior / side effects

Copy the set into a new mutable set.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = {1, 2}
copied = seen.copy()

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.clear_method

Remove every value from the set.

Syntax

set.clear()

Parameters

None

Returns

None — No direct return value. The set becomes empty.

Behavior / side effects

Remove every value from the set.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = {1, 2}
seen.clear()

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.for_loop

Iterate values in stable insertion order.

Syntax

for value in set:

Parameters

NameDescription
valueAny?
Current set value in the loop.
Required · Positional or named
No default
setset
set to iterate.
Required · Positional or named
No default

Returns

None — No direct return value. The loop runs once per value.

Behavior / side effects

Iterate values in stable insertion order.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

values = {"home", "shop"}
for value in values:
    text(value)

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs

set.truthy_check

Check whether the set has at least one value.

Syntax

if set | if not set

Parameters

NameDescription
setset
The set used in the condition.
Required · Positional or named
No default

Returns

Boolean condition — true when the set is not empty, false when it is empty.

Behavior / side effects

Check whether the set has at least one value. An empty set is treated as false.

Execution

  • Blocking: No
  • Thread safety: Use separate objects per flow
  • Parallel execution: Yes

Value operations execute in the calling flow without an intentional wait for capture, gesture completion, or user input. Create mutable containers/builders separately in each flow; this is isolation, not a shared-object synchronization guarantee.

Example

seen = set()
if not seen:
    text("empty")

Errors / limitations

No additional limitations documented; follow the parameter and behavior contract above.

Related APIs