Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List comparison in Python
#11
@Vysero : ok let me elaborate . Taking this example :
if " vlan 158 " of list a is present anywhere in list b then "ignore".same for list b (if " vlan 158 " of list b is present anywhere in list a then "ignore").
"vlan 159 " of list b is not available anywhere in list a , so it should return remaining element along with first element.So it should say list a is below missing config . 

['vlan 159', '  name SALES', '  mode vpc']


In short if first element ( vlan id : vlan 158 ,vlan 159 etc ) of a list is present in other list then ignore and vice versa , if not then return with remaining element .
Reply
#12
Hrm, so if I have this right then your looking for something like this:

a = [['vlan 158', '  name MARKET', '  mode vpc']]
b = [['vlan 158', '  name MARKETING', '  mode vpc'], ['vlan 159', '  name SALES', '  mode vpc']]


def check_contents(list_one, list_two):
  shorter, longer = sorted([list_one, list_two], key=len)
  for x in longer:
    if not x:
      continue
    for y in shorter:
      if not y:
        continue
      if x[0] != y[0]:
        print(x)

check_contents(a, b)
Output:

['vlan 159', '  name SALES', '  mode vpc']
Reply
#13
Thanks
Reply
#14
(Aug-09-2018, 02:42 PM)Nirmal Wrote: Thanks

Sure no problem!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo String comparison in a csv file in Python Pandas fleafy 2 1,107 Nov-18-2022, 09:38 PM
Last Post: fleafy
  LIST or ARRAY Comparison and change of value nio74maz 0 1,668 Dec-21-2020, 05:52 PM
Last Post: nio74maz
  Python greater than equal to comparison operator Ilangos 4 2,356 Sep-26-2020, 03:53 AM
Last Post: buran
  Comparison Operator "is" idle vs python command spisatus 3 2,736 Oct-29-2019, 10:00 PM
Last Post: DeaD_EyE
  iterate through a list with comparison of expression Alexandro 6 3,345 Jan-31-2019, 05:16 PM
Last Post: Scorpio
  Python 2.7 LooseVersion version comparison unexpectedly fails kwutzke 5 4,079 Nov-27-2018, 10:23 AM
Last Post: kwutzke
  List comparison in Python Nirmal 4 3,040 Sep-26-2018, 06:23 PM
Last Post: nilamo
  rpm version comparison in python asad 3 3,719 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