Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95035 > unrolled thread

QUEST: does HACKING make FOR loop quicker.

Started byJohn Doe <z2911@bk.ru>
First post2015-08-05 23:00 +0300
Last post2015-08-05 23:00 +0300
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  QUEST: does HACKING make FOR loop quicker. John Doe <z2911@bk.ru> - 2015-08-05 23:00 +0300

#95035 — QUEST: does HACKING make FOR loop quicker.

FromJohn Doe <z2911@bk.ru>
Date2015-08-05 23:00 +0300
SubjectQUEST: does HACKING make FOR loop quicker.
Message-ID<mailman.1246.1438807229.3674.python-list@python.org>
Presumption
------------------------------------------------------------------------
1. Lists are mutable sequences.
2. There is a subtlety when the sequence is being modified by the FOR 
loop (this can only occur for mutable sequences, i.e. lists)


Preamble
=====================================================================
To pass by reference or by copy of - that is the question from hamlet. 
("hamlet" - a community of people smaller than a village python3.4-linux64)

xlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
i = 0
for x in xlist:
     print(xlist)
     print("\txlist[%d] = %d" % (i, x))
     if x%2 == 0 :
         xlist.remove(x)
     print(xlist, "\n\n")
     i = i + 1

So, catch the output and help me, PLEASE, improve the answer:
Does it appropriate ALWAYS RE-evaluate the terms of the expression list 
in FOR-scope on each iteration?
But if I want to pass ONCE a copy to FOR instead of a reference (as seen 
from an output) and reduce unreasonable RE-evaluation, what I must to do 
for that?
========================================================================


Assumption. Wind of changes.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sometimes FOR-loop may do a global work. (depends on size of expression 
list)
Sometimes on external DB. (just a joke)

So, what can FOR-loop do for You, depends what can You do for expression 
list, which can be mutable far outside YOUR NICE LOGIC.


QUEST
************************************************************************
Your example of FOR-loop with a simple logic and sensitive information, 
operated by means of external list-array and Your elaborative vision of 
hacking possibilities through mutation of a list's terms.

TIA
RSVP

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web