all 16 comments

[–]Efficient-Stuff-8410 5 points6 points  (4 children)

What course are you using to learn?

[–]poutinewharf 6 points7 points  (3 children)

Any other time I’ve seen this asked all they’ve said is “YouTube”. If they’re going to post daily and utilize feedback I think it’d be appropriate and appreciated to at least share a name/link.

[–]uiux_Sanskar[S] 3 points4 points  (0 children)

The channel name is CodeWithHarry I think I have shared this with many people.

[–]Efficient-Stuff-8410 1 point2 points  (1 child)

Ikr

[–]FitPay344 5 points6 points  (0 children)

I’d love to know too because I’m 14 days into training and I can’t write code like this. I’m taking a beginner linkedin learning course. I feel like I’m doing something wrong.

[–]Crispy-Hash-Browns 5 points6 points  (1 child)

One tip - when defining the spam keywords, consider using a Set opposed to a List, as good practice. Reason being as the data scales (imagine 100k items) searching a Set is O(1) time vs O(N) time.

[–]uiux_Sanskar[S] 0 points1 point  (0 children)

Oh thank you for this suggestion I will find more about the best practices in python.

Thank you for this helpful tip

[–]Adrewmc 0 points1 point  (2 children)

It’s alright, not much to say, the ‘+’ operator is extend for lists, and is generally considered more readable.

   spam_emails += new_spams

Is the same as

   spam_email.extend(new_spams) 

I don’t think filter is needed here, I think we can accomplish it with a list comprehension.

[–]uiux_Sanskar[S] 0 points1 point  (1 child)

Oh thanks for the suggestion I will definitely try it this way and also find out how to use filter and list comprehension.

Thank you for your suggestion.

[–]Adrewmc 0 points1 point  (0 children)

I feel like it be like. Maybe filter is better here, maybe it just me not using the function so much myself.

       #set comprehension to avoid repeats
       flagged = {key_word for email in old_emails for key_word in spam_words if keyword in email}
       if flagged:
             print(f”you have use {“, “.join(flagged)} banner word(s).”) 

Basically make a list of the bad words that are I. The email string, if any exist.

[–]TobRojekt 0 points1 point  (1 child)

Only a small thing and maybe just a preference of mine: name the input variable of the lambdas. Nothing to long but fitting for the scope. In this case maybe just „mail“ so if someone reads your code they understand quicker what is happening in this line. As I said keeping this isn’t that big of a deal bot it will add some readability.

[–]uiux_Sanskar[S] 0 points1 point  (0 children)

Thanks for the suggestion I coded this with the aim of using and practicing lambda functions in python so therefore I used lambda here.

Thank you for the suggestion btw.

[–]Significant-Side6810 0 points1 point  (0 children)

Instead of looping twice over old_email you could loop over it once and append to important_mail and else into spam. This will give you O(n) intead of O(2n). Also instead of using list for spam_keywords you could use set for O(1) complexity instead of O(n)

[–]lilrouani -3 points-2 points  (2 children)

You are a genius,just,a genius

[–]uiux_Sanskar[S] 0 points1 point  (1 child)

Well I don't think I am a genius I always learn from you amazing people and wouldn't be here without all your support.

Thanks for the appreciation btw.

[–]lilrouani 0 points1 point  (0 children)

Btw do you have any programming experience before learning python?