Jose' Matos wrote: > On Tuesday 10 August 2004 12:23, Angus Leeming wrote: >> Ok, Jose. The ignorant one strikes again. >> >> How do I initialise a list of 25 items to 0? >> In C++ >> std::vector<int> path_bins(25, 0); >> >> In python, I've got: >> >> path_bins = [] >> for i in range(0, 25): >> path_bins.append(0) >> >> which feels 'sub-optimal' ;-) > > path_bins = [0] * 25 > > This works for all types whose addition is defined. You know if n > is an > integer then a * n will be a+....+a (n times), quite natural. :-) > > This is one of the reasons why I like python.
Thanks you, both. I'm reminded of the learning curve that I had to climb for C++. It all feels natural now, but then it was a little... baffling ;-) -- Angus