Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List comparison in Python
#10
(Aug-05-2018, 02:16 PM)Nirmal Wrote: So the first element of "list a" ( e:g vlan 158" in this case ) has to be checked in "list b" and vice versa and if it is found then fine. If it is not found ( e:g vlan 159 ) is not available in "list a" then it should return everything i.e "list a " has below

When you say: "has to be checked in "list b"" are you meaning the first element of "list a" needs to be checked against the first element of each list in "list b"? S/T each matching instance can be ignored but none matching instances will result in a 'print' of the remaining elements in that list? For instance the program would for:
a = [['vlan 158', '  name MARKET', '  mode vpc'], []]
b = [['vlan 158', '  name MARKETING', '  mode vpc'], ['vlan 159', '  name SALES', '  mode vpc']]
produce the output:

#first element of list a matches first element of list b thus ignore
name SALES, mode vpc #first element of list a does not match second element of list b thus print
name MARKETING, mode vpc #second element in list a is an empty list thus will not match first element in list b thus print
name SALES, mode vpc #second element in list a is an empty list thus will not match second element in list b thus print
Reply


Messages In This Thread
List comparison in Python - by Nirmal - Aug-03-2018, 04:17 PM
RE: List comparison in Python - by Larz60+ - Aug-03-2018, 04:34 PM
RE: List comparison in Python - by Nirmal - Aug-03-2018, 06:45 PM
RE: List comparison in Python - by Vysero - Aug-03-2018, 07:43 PM
RE: List comparison in Python - by Nirmal - Aug-04-2018, 08:32 AM
RE: List comparison in Python - by wavic - Aug-04-2018, 08:47 AM
RE: List comparison in Python - by Nirmal - Aug-04-2018, 04:54 PM
RE: List comparison in Python - by Larz60+ - Aug-04-2018, 07:22 PM
RE: List comparison in Python - by Nirmal - Aug-05-2018, 02:16 PM
RE: List comparison in Python - by Vysero - Aug-06-2018, 04:43 PM
RE: List comparison in Python - by Nirmal - Aug-07-2018, 07:38 AM
RE: List comparison in Python - by Vysero - Aug-07-2018, 05:26 PM
RE: List comparison in Python - by Nirmal - Aug-09-2018, 02:42 PM
RE: List comparison in Python - by Vysero - Aug-09-2018, 04:30 PM

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