rmotr-curriculum / post-your-question-questions

0 stars 0 forks source link

for loop statement #58

Closed victorbizpetrol closed 6 years ago

victorbizpetrol commented 6 years ago

I have seen this for loop statement used a few times at rmotr, but I have not been able to figure out how to use it or where the syntax instructions are. I have included the two examples I seen so far.

Assignment: http://learn.rmotr.com/python/post-a-question/post-your/questions

User code:

'''
I have seen this for loop statement used a few times at rmotr,
but I have not been able to figure out how to use it or where
the syntax instructions are.  I have included the two examples I 
seen so far.
'''

#EXample 1 
def invert_dict(a_dict):
    return {value: key for key, value in a_dict.items()}

#Example 2: from hangman/main.py 
def build_list_of_words(words, default_list):
    if words:
        return [w.strip() for w in words.split(',')]
    return default_list
santiagobasulto commented 6 years ago

Hello Victor! That's actually a list comprehension, that will be covered in Unit 8. We try to put a comment every time we use some piece of code from a more advanced unit, we've clearly forgotten here. I'll put those. Our idea is to show them early so they make a little bit more sense later, but always with a word of caution.

We'll also talk a lot about these when using Numpy and pandas with vectorized operations.

victorbizpetrol commented 6 years ago

Thanks!

Victor Castillo 310-210-4571 [p-logo-light-uppercase]

From: Santiago Basulto notifications@github.com Reply-To: rmotr-curriculum/post-your-question-questions reply@reply.github.com Date: Sunday, September 2, 2018 at 1:20 PM To: rmotr-curriculum/post-your-question-questions post-your-question-questions@noreply.github.com Cc: Victor Castillo victor@bizpetrol.com, Author author@noreply.github.com Subject: Re: [rmotr-curriculum/post-your-question-questions] for loop statement (#58)

Hello Victor! That's actually a list comprehension, that will be covered in Unit 8. We try to put a comment every time we use some piece of code from a more advanced unit, we've clearly forgotten here. I'll put those. Our idea is to show them early so they make a little bit more sense later, but always with a word of caution.

We'll also talk a lot about these when using Numpy and pandas with vectorized operations.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/rmotr-curriculum/post-your-question-questions/issues/58#issuecomment-417957118, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJlzTfOLuVG_ncOgt8CFN0ON9IiAVZprks5uXD2AgaJpZM4WWdwQ.