Two lists can be concatenated to combine as one list. We cannot add a list to a range, so you are correct to cast it as a list, first.
Above the error message indicates you are attempting to concatenate a list with a zip object. This we cannot do. A zip object is an iterator, not a list.
can someone give me guidance. I’m not understanding why my code isn’t working.
i keep getting an error the following error "Did you combine age with the list [32, 41, 29] and store the result in all_ages ? all_ages should begin with 32, 41, 29 and end with 42".
Hello! I’ve recently started to learn Python and I would like someone to help me.
Could anyone tell me how to make a combined list that includes the information about ‘id’, ‘name’ and ‘age’ all together in one parenthesis? One element of the list would be like this; (0, ‘Ainsley’, 32). I tried to make the list by using zip(), but still no luck.
Why do I have to change the type of both the zip and range to list when I want to print them, but I do not have to do change into a list type if I want to use them in a calculation, like here:
A lot of python functions are designed to accept so-called iterable objects as arguments. Iterable includes both regular sequences like a list where every element is already stored in memory and certain objects like range which won’t necessarily store every single integer within that range in memory, instead it is set up to return each item individually. There functions effectively unpack such iterators for you.
On the other hand print just outputs the representation of an object, it is not designed to unpack an iterable itself. So a zip or range object will return some details about the object itself rather than the items that would be returned if it they were iterated through. A list on the other hand already exists in memory so it’s representation can easily show at least part of the contents of the list.
Apologies if that’s a bit vague but you’d need to know quite a bit about Python’s iterator and sequence objects before it’s clear.
I was going back to review some things and I was wondering is there a way to take three lists and make them into a 2D list. I know I can create a 2D list with zip but that makes it a tuple right?
There’s nothing in the base language to do this on a single line (that I can think of) but basic forms of iteration should be able to get your a list of lists without too much trouble. Loops should be introduced shortly in the course which would be a decent option (e.g. you loop through the zip and assign each iteration to a list).
In truth, you would be the best one to tell us why. If you are willing to lay out your ideas, and accept criticism, then the solution will unfold that includes your contribution.
to my understanding, gradebook is a 2D list indicated by the brackets within brackets: gradebook=[[physics,98]]etc.
when I call gradebook.remove([2][1]) I am referencing [“poetry”, 85] in an attempt to remove the 85. It’s a list because of the square brackets and the comma that separates it, right? I defined gradebook as a list earlier in the code.
I got through the lesson because I used a different method, but I’m still confused on how that index is not within range/ there’s an error.