Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Difference between two lists in python

Hi there,

I have been working my way through all the lessons but I have been thinking out of the box and been experimenting with APIs etc. to test my skills. One problem I have come up against and I just can't find a easy (or straight forward) answer. When I poll a specific API I load it into a list then to a file, then every hour I check again and I want to see if anything changed from the previous check if something is different I go off and execute a change to update another part of my script.

Is there any easy way of comparing the "live" data just pulled to the contents in the stored file then act on the change?

I hope that makes sense and that someone can help! Thanks,

Euan

3 Answers

Steven Parker
Steven Parker
243,215 Points

At first look, this seems that it would be very easy. If you have the old sample in a list, and you load the new one into a new list, just compare the lists (not the files) against each other for equality.

Or am I missing something?

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

Check out the Python difflib module — Helpers for computing deltas

Hi guys thanks, I managed to compare the two lists using python if item is not...

and that then returned the item that was not in the other list and it worked but I will look at the difflib module for another problem I have!

Thanks