Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List comparison in Python
#1
HI

I have two list . i want to compare with each other with the list index[1][2][3] of each list with other list .If its a match then ignore , if not the return the whole list.

a = [['Eth1/1/13', 'Marketing', 'connected', '10', 'full', 'a-1000'], ['Eth1/1/14', 'NETFLOW02', 'connected', '10', 'full', '100']]

b = [['Eth1/1/13', 'NETFLOW02', 'connected', '15', 'full', '100'], ['Eth1/1/14', 'Marketing', 'connected', '10', 'full', 'a-1000']]
Expected Output :

Diff a:

Eth1/1/14  NETFLOW02   connected    10   full    100

Diff b:

Eth1/1/13  NETFLOW02    connected    15   full    100
My Code :

p = [i for i in a if i not in b]
for item in p: 
        print item[0]
print "\n++++++++++++++++++++++++++++++\n"
q = [i for i in b if i not in a]
    for item in q: 
        print item[0]
Any idea ?
Reply


Messages In This Thread
List comparison in Python - by Nirmal - Sep-26-2018, 09:33 AM
RE: List comparison in Python - by woooee - Sep-26-2018, 01:14 PM
RE: List comparison in Python - by Nirmal - Sep-26-2018, 01:54 PM
RE: List comparison in Python - by woooee - Sep-26-2018, 06:21 PM
RE: List comparison in Python - by nilamo - Sep-26-2018, 06:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo String comparison in a csv file in Python Pandas fleafy 2 1,253 Nov-18-2022, 09:38 PM
Last Post: fleafy
  LIST or ARRAY Comparison and change of value nio74maz 0 1,747 Dec-21-2020, 05:52 PM
Last Post: nio74maz
  Python greater than equal to comparison operator Ilangos 4 2,545 Sep-26-2020, 03:53 AM
Last Post: buran
  Comparison Operator "is" idle vs python command spisatus 3 2,868 Oct-29-2019, 10:00 PM
Last Post: DeaD_EyE
  iterate through a list with comparison of expression Alexandro 6 3,524 Jan-31-2019, 05:16 PM
Last Post: Scorpio
  Python 2.7 LooseVersion version comparison unexpectedly fails kwutzke 5 4,278 Nov-27-2018, 10:23 AM
Last Post: kwutzke
  List comparison in Python Nirmal 13 6,689 Aug-09-2018, 04:30 PM
Last Post: Vysero
  rpm version comparison in python asad 3 3,875 Jul-27-2018, 01:00 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020