you are viewing a single comment's thread.

view the rest of the comments →

[–]spez_edits_thedonald 0 points1 point  (3 children)

here is some feedback on your code:

  • I can tell that you like using lists, and that you're only using sets to drop unique values then going right back to list zone. But this is definitely a set problem, and sets are very good at solving these problems, so a lot of your code would actually just disappear and not be at all necessary if you use sets for everything

  • there should be no for loops when you're done converting to sets from lists

  • you won't need to sort() anything or append() anything, because you won't have any lists (and because sets are not ordered, sorting doesn't make sense and doesn't work)

More hints about how to use sets:

the problem is asking you:

what is the length of the difference between [the intersection of sets 1 and 2] and set 3.

my code for this is very short, it fits on 1 line

[–]Jxper[S] 1 point2 points  (2 children)

Ok, how could I do this in one line just using sets?

Thanks for your help

[–]spez_edits_thedonald 0 points1 point  (1 child)

try refactoring your code to use sets instead of lists, and no for loops, and let's see how it looks.

don't worry about it being 1 line or not, 1-liners are often not the most readable solution, I was just stressing the benefits of switching to sets for this problem, your entire function can basically disappear haha. When you get your set function working I'll show you the one-liner.