October 24th, 2013, 02:05 PM
How can i fill up an empty list using 'for' ?
#my failed attempt:
for item in range(len(mylist)):
The idea is that i want to start adding new items to an empty list, i want to grow my list progressively.Later,when i understand the specific example, i will make a more general code by using input() instruction so that the user will input whatever data.
October 24th, 2013, 03:11 PM
# learn to use the documentation!!!
# >>> help(list)
for item in 'abcdef': # len(your_list) is 0. The block of code within the loop would have exectuted 0 repetitions
your_list.append(math.log(2,10)*i) # append method of list
constant = math.log(2,10)
my_list = [constant*i for i in range(6)] # list comprehension
assert my_list == your_list
Last edited by b49P23TIvg; October 24th, 2013 at 03:13 PM.
[/code] are essential for python code and Makefiles!
October 24th, 2013, 05:59 PM
i need to buy myself a new pair of eyes
Originally Posted by b49P23TIvg