Create a list of integers from from a (inclusive) to b (inclusive).
Example:
integers(2,5) returns [2, 3, 4, 5].
I know this is probably an easy one, but I just can’t seem to get anything to work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To explain your own solution:
irefers to the number itself;[i]is a list with one element,i. When using the+operator for lists, Python can concat two lists, so[1, 2] + [3, 4]is[1, 2, 3, 4]. It is however not possible to just add a single element (or number in this case) to an existing list. Trying so will result in aTypeError.What you could do instead of concatenating with a one-element list, is simply append the element by using the method with the same name:
One final note, you should not name your variable
list(ordictorstretc) as that will locally overwrite the references to the built-in functions/types.