April 8, 2020 at 12:00 am
Comments posted to this topic are about the item Difference Between Lists
April 8, 2020 at 5:41 am
Nice question, thanks Tyler
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
April 8, 2020 at 6:59 am
Here states different:
A.difference(B) it's the same as A-B
April 8, 2020 at 1:19 pm
Thanks for the question, learned something new today. As always, and to the bane of cat lovers, there are many ways to skin a cat... I didn't know about the difference function for sets so my natural inclination was to use a conditional comprehension...
unused = [item for item in registered_ids if item not in recent_login_ids]
Is there an advantage to using set.difference or is it just preference? I suspect performance would work better since sets are ordered and unique but I don't know.
-
April 8, 2020 at 2:06 pm
Here states different:
A.difference(B) it's the same as A-B
Hey Carlo, thank you for the feedback! That is the same when working with sets, it's important to look at the data types of our variables. In this example, we would need to do some conversion to use the "-" operator.
Thanks for the question, learned something new today. As always, and to the bane of cat lovers, there are many ways to skin a cat... I didn't know about the difference function for sets so my natural inclination was to use a conditional comprehension...
unused = [item for item in registered_ids if item not in recent_login_ids]Is there an advantage to using set.difference or is it just preference? I suspect performance would work better since sets are ordered and unique but I don't know.
Your approach seems to be the faster solution here. I did some timeit tests to confirm. Excellent approach and solution! I wonder if this flip flops based on the size of the list/set.
April 8, 2020 at 2:26 pm
Here states different:
…
Your approach seems to be the faster solution here. I did some timeit tests to confirm. Excellent approach and solution! I wonder if this flip flops based on the size of the list/set.
Thank you much for the "timeit" hint, very useful. I suspect you're right, given the small size and the fact that the example lists were already ordered and unique the conversions from list to set and back to list for the difference function probably added overhead that would be negligible with larger sets of data. Time permitting, I think I'll try to test a scenario and see. Thanks for giving me something to practice with.
-
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply