seen [terminology]
Terminology¶
Usage¶
- Use for values, states, keys, or remainders encountered before.
- It commonly supports:
- Duplicate detection
- Cycle detection in generated states
- Recurring-decimal detection
- Value-to-position lookup
- It does not necessarily imply that a graph node has been fully processed.
seen = set()
while n != 1 and n not in seen:
seen.add(n)
total = 0
while n > 0:
n, digit = divmod(n, 10)
total += digit * digit
n = total
See 202. Happy Number.