Code Visual to Flowchart is a version that allows you to visualize your code and save it to html, xml and text files.A simple code visualization that gives the programmer an overview of the program by displaying the code as a flow chart.
]]> Visual to Flowchart has completed downloading from SourceForge.net. You can now get it using the Windows Get it button.Q:
Generate a list of python objects
Is there a pythonic way to generate a list of objects (can be Lists or Dictionaries, any of them that will be accepted by other parts of the system) without creating new objects? Something like this:
a = [Camel() for i in xrange(20)]
When I do this I am creating new objects, which is bad if I have something to iterate over them, because I will have to stop and garbage collect the objects when I'm done.
Thanks for the help!
A:
What you're after is itertools.repeat, which is basically a decorator for the repeat() function:
>>> from itertools import repeat
>>> a = repeat('a',10)
>>> list(a)
['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
The version of repeat() used here will repeat the supplied iterable multiple times (unless you tell it to stop, by specifying a count argument in the repeat() function's call).
Use repeat:
>>> import itertools
>>> a = list(itertools.repeat(1, 10))
>>> a
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> len(a)
100
>>> a[-1]
1
>>> a[-2]
Related links:
Commentaires