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
Creation Method
Create an empty set or collect unique values from another iterable, including a generator expression.
Syntax
set()
set(iterable, /)
Parameters
Name
Description
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.
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.
Build a set by looping through an iterable and keeping unique calculated values.
Syntax
{expr for target in iterable if condition}
Parameters
Name
Description
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.
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.
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.
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.
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.
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.
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.
Add values from one or more iterables into the set.
Syntax
set.update(*iterables)
Parameters
Name
Description
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.
Return a new set with values from this set and the provided iterables.
Syntax
set.union(*iterables)
Parameters
Name
Description
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.
Return a new set containing values that also exist in every provided iterable.
Syntax
set.intersection(*iterables)
Parameters
Name
Description
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.
Return a new set without values found in the provided iterables.
Syntax
set.difference(*iterables)
Parameters
Name
Description
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.
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.
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.
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.
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.