[python]To find out difference between two list

Use case
You have an actual name list you need to deploy software to through automated tool such as KACE by Quest software. You received a report no the number of people actually received the software and you need to know the actual percentage of software deployed.

Possible solution
set() removes duplicates, and is unordered, we use set() because we can use arithmetic operator to check the difference between two list.

actual_name_list_for_deployment = ['abc', 'cde', 'fgh', 'ijk', 'lmn']
deployed_name_list = ['abc', 'lmn']

diff = set(actual_name_list_for_deployment) - set(deployed_name_list)
print('The list of people not deployed is {}'.format(diff))
print('The actual deployment is {}% of the {} people in the actual name list, {}% has not received the software'.format(
    str((len(deployed_name_list)/len(actual_name_list_for_deployment) * 100)),

Screenshot 2019-05-14 at 1.36.25 PM
You can replace the static lists with the actual file by opening the files and store the file object to another variable and you can use set() to create a pair of set object, minus the original list with the list reported by your server, then print out the percentage.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s