I'm a first-year computer science student and I'm really struggling with lists and matrices in Python. We have some restrictions for our class assignments, like not using return statements to exit loops, not using pop with arguments, and only basic functions like len(), ord(), and chr(). I'm not sure how to manipulate lists effectively, like shifting or sorting elements. Matrices are presented to us as lists of lists, and I'm confused about that too. Any advice on how to better understand the logic behind lists and matrices would be greatly appreciated. I'm determined to improve, and I know everyone starts somewhere!
4 Answers
I suggest checking out W3Schools' Python lists section. It's a good starting point! When you hit obstacles, try to be specific about what you're struggling with. The clearer you are, the better the help you'll get.
First off, Python has some great built-in functions that can really help you understand lists. Try using `dir([])` to see all the methods available for lists, and `help([])` for documentation on them. This can give you insights on how to work with lists. Regarding matrices, could you clarify if you're using numpy? If not, remember a matrix can just be a list of lists! That might help clarify things!
Thanks for your input! We're actually viewing matrices as 'lists of lists' in class, so that helps!
A fun way to grasp shifting elements in an array is to use a piece of paper. Draw boxes, number them, and place small items in them. To shift elements, move each item to the right by one box, while keeping the order intact. For sorting, you can compare two items at a time and swap them when needed. Writing each step can reveal patterns and help you understand! This hands-on approach might clarify things for you.
This is a really helpful approach! I hadn't thought about using visuals like that. Thanks for the suggestion!
Just do a quick Google search for 'Python lists' and you'll find tons of resources. There are also interactive sites where you can practice coding directly. If you're still struggling, consider asking an AI for explanations and then try coding it based on what you learned from it.

I appreciate the suggestion! I need to work on being more specific, especially with index logic and loops.