Skip to content

refactor(maths): use direct iteration instead of index-based loops in persistence.py#14767

Open
fauzan171 wants to merge 1 commit into
TheAlgorithms:masterfrom
fauzan171:fix/persistence-use-pythonic-iteration
Open

refactor(maths): use direct iteration instead of index-based loops in persistence.py#14767
fauzan171 wants to merge 1 commit into
TheAlgorithms:masterfrom
fauzan171:fix/persistence-use-pythonic-iteration

Conversation

@fauzan171
Copy link
Copy Markdown

Summary

Replace for i in range(len(numbers)) with for number in numbers in both multiplicative_persistence() and additive_persistence() functions.

Changes

  • Use direct iteration (for number in numbers) instead of index-based loops (for i in range(len(numbers)))
  • Applies to both multiplicative_persistence() and additive_persistence()

Why

Direct iteration is more Pythonic (PEP 20: Simple is better than complex) and avoids unnecessary index lookups (numbers[i]). The behavior is unchanged and all existing doctests pass.

Checklist

  • All doctests pass
  • No behavioral changes

… persistence.py

Replace for i in range(len(numbers)) with for number in numbers in both multiplicative_persistence() and additive_persistence(). Direct iteration is more Pythonic and avoids unnecessary index lookups.
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant