List comprehension exercises

Welcome to the Get Help category!

This is where you can ask questions about your code. Some important things to remember when posting in this category :slight_smile:

  • Learn how to ask a good question and get a good answer!
  • Remember to include a link to the exercise you need help with!
  • If someone answers your question, please mark their response as a solution :white_check_mark:
  • Once you understand a new concept, come back and try to help someone else!

I’m not sure if this is the best way to ask this but I’m still pretty new to coding, still working on learning Python 3 and doing pretty well at it, however every time a list comprehension comes up I utterly fail at it. I’ve been back over the exercises that cover this in ‘learn Python 3’ I don’t even know how many times, read some of the forums on it but for some reason my brain is literally just not taking it in. I was wondering if there are other exercises on here to do to hardwire it to my brain or maybe an external link that would describe it better or another place that just simply has like unlimited exercises just on list comprehension so that I’m not struggling with something that is highly used in Python. I hate when I get stuck on something and I am ok with a bunch of other things say in an exercise and then dread the one thing in this case list comprehension and then feel like I’m stuck on it. Any help would be so useful to get past this.

I totally understand the confusion.

One thing that might help is to have a look at the Python Documentation:

While I know that the docs might seem a little daunting or confusing at first, it really is the Holy Grail of explanations. (See what I did there? {Monty} Python, Holy Grail? Ah, but I digress).

From the docs: " A list comprehension consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses."

So…list comprehensions are a more succinct way of creating another list. There’s a lot of discussion/threads about it on the forums too that can be found using :mag: that may be of use for you.

But, my suggestion is to just write them in a code editor. Make some up and see what happens with your code, fix the errors, write it again. The basic structure is: ]expression for item in list] .

1 Like

Thanks I will definitely try both of those. I also found some decent in person explanation on Youtube that helped my brain absorb it better and made it make a bit more sense. Sometimes I learn better literally others visually. This one seemed to click easier watching a descriptive video on it. Not sure why that took so long lol I am always hounding people asking stuff ’ Did you you check Youtube? '. Anyways thanks for the reply and the help.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.