help me please. ineed a valubal answer
is thid correct
to_21 = range(1,22)
odds = to_21[::2]
middle_third = to_21[7:14]
and bye coz i need to go to sleep its midnight
to_21 = range(1,22) doesn’t create a list with the numbers 1 to 21 to do that you could use list(range(1,22)) or to_21 = [x for x in range(1,22)]. The rest is fine.
In Python 2 it does. This site uses Python 2.7.x.
is Python 3.x.
List comprehensions are not covered until the Advanced Topics unit.
You’re right @mtf. I forgot they’re using Python 2. Mainly because I searched for the exercise in question and could not find it because I couldn’t remember how it was done in the exercise. I know it’s there somewhere. But anyway thanks for reminding me. @digitalninja71913 it’s right.
As it turns out, this IS from the advanced topics module.
The beauty of programming with a language such as Python (or JS or Ruby, etc.) is that there are multiple ways to accomplish the same end. Some may be more elegant, some more efficient.
For the above problem,
range and list slicing is all that’s needed. The OP is using the simplest method.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.