Python: Advanced Topics in python


#1

Good Afternoon Friends,I am confused by this challenge https://www.codecademy.com/en/courses/python-beginner-en-KAgt5/3/1?curriculum_id=4f89dab3d788890003000096.
I don't understand why does the list consists of zero.


#2

the list doesn't consists of zeroes?


#3

This is the ouput shown in my window

[0, 3, 6, 9, 12, 15]

#4

a list consisting of zeroes would be:

[0, 0, 0, 0, 0]

list comprehension is just a for loop inside a list. Think about a loop, where you append numbers divisible by 3 to the list


#5

Can you explain me what is the logic used in the next challenge
https://www.codecademy.com/en/courses/python-beginner-en-KAgt5/3/2?curriculum_id=4f89dab3d788890003000096#
I am completely befuddled by this lambda thing.Thank you very much in advance


#6

lambda is just a single line function. See if you can find the similarities between normal functions and lambdas


#7

I tried to make a normal function to compare with lambda. Can you please check

def lang(list):
    for i in languages:
        if i=="Python":
            print i
            
print lang(languages)

#8

def lang(lst):
    result = []
    for i in lst:
        if i=="Python":
            result.append(i)
    return result
            
print lang(languages)

i think this is closer. or somethingl ike this:

def lang(lst):
    for i in lst:
        if i !="Python":
            lst.remove(i)
    return lst
            
print lang(languages)

not sure which mimics lambda better


#9

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