-4

My apologies as I'm new to Python and struggling with list comprehensions.

I can make a simple list in the following way:

min = whatever arbitrary number (not integer)
step= whatever arbitrary number (not integer)
lower_bound[0] = min
for index = 1 to 9
    lower_bound[index] = lower_bound[index-1] + step

How do I be more Pythonic with list comprehension? Also, what is a good resource on the basics of list comprehension? Thanks.

P. Sheih
  • 13
  • 3
  • 2
    Possible duplicate of [python list comprehension explained](http://stackoverflow.com/questions/20639180/python-list-comprehension-explained) – juanpa.arrivillaga Feb 08 '17 at 02:57
  • 2
    The code you've posted is not valid python. – juanpa.arrivillaga Feb 08 '17 at 02:58
  • list comprehension creates a new list, in your code you are modifying a list, which do you want? – Steven Summers Feb 08 '17 at 02:59
  • Nor does it make sense. What is the point of `min = 0`? You never change its value, and `0 + step` is always equal to `step`. – Blorgbeard Feb 08 '17 at 02:59
  • You shouldn't use the names of built-in Python functions to name your variables (i.e. don't use `min` to denote your "minimum" variable, as `min` is a Python built-in). – blacksite Feb 08 '17 at 03:02
  • List comprehensions are good for mapping a function across an iterable, filtering on some predicate, or a combination of both of those things. You can always achieve the same thing with a for-loop, and oftentimes it is more Python to use a loop. I would concentrate on mastering loops if I were you. – juanpa.arrivillaga Feb 08 '17 at 03:03
  • this sight may help you - http://www.python-course.eu/list_comprehension.php – Rehan Shikkalgar Feb 08 '17 at 03:03
  • My apology for a poorly framed question, and my appreciation for everyone's input. This is what I wanted to accomplish (with list comprehension): lb=[minimum + step*i for i in range(9)] – P. Sheih Feb 08 '17 at 07:05

1 Answers1

0
minimum = 0

step = 2


lower_bound = [i for i in range(minimum, 9, step)]

print(lower_bound)

Is this what you were asking for?

n12312
  • 70
  • 1
  • 6