In C, it's a common pattern to use temporary variables in an lexical
scope to prevent the global scope from getting dirty.
For example,

int a[N];
for (int i = 0; i < N; i++) {
  int temp = ...
  a[i] = ... // something got from temp
// temp do not exists here

But in python, such a pattern seems impossible. An straightforward
translation should be like this:

a = []
for i in range(N):
    temp = ...
    a.append(...)# something got from temp
# temp DO EXISTS here, will be the value of the last iteration

As in the comment, the temporary variable remains existing after the
block. How do you usually deal with this?
Tutor maillist  -
To unsubscribe or change subscription options:

Reply via email to