Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] list content check
#1
Hi,

I've a very naïve question, is there a simplier way to test a list content?b Smile
(solution#2 does the job in a single line)

Paul

MyList = ['xxXx', 'YyYy']

# solution 1
MyList_intermediate = [element.lower() for element in MyList]
Check1 = True if "zzzz" in MyList_intermediate else False
Check2 = True if "xxxx" in MyList_intermediate else False

# solution 2
Check3 = True if True in [True if ("zzzz" in elem.lower()) else False for elem in MyList ] else False
Check4 = True if True in [True if ("xxxx" in elem.lower()) else False for elem in MyList ] else False
Reply


Messages In This Thread
[solved] list content check - by paul18fr - Jan-03-2024, 02:10 PM
RE: list content check - by buran - Jan-03-2024, 02:46 PM
RE: list content check - by paul18fr - Jan-03-2024, 04:02 PM
RE: list content check - by deanhystad - Jan-03-2024, 09:59 PM
RE: list content check - by Pedroski55 - Jan-04-2024, 10:01 AM
RE: list content check - by paul18fr - Jan-04-2024, 10:16 AM
RE: [solved] list content check - by deanhystad - Jan-04-2024, 11:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 474 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,523 Mar-24-2023, 08:34 AM
Last Post: fullytotal
  [SOLVED] [sqilte3] Check if column not empty? Winfried 5 1,163 Jan-28-2023, 12:53 PM
Last Post: Winfried
  Check if clients are online with ips stored in json [SOLVED] AlphaInc 6 2,566 Jun-27-2022, 08:28 AM
Last Post: AlphaInc
  check if element is in a list in a dictionary value ambrozote 4 2,044 May-11-2022, 06:05 PM
Last Post: deanhystad
  Loop through list of ip-addresses [SOLVED] AlphaInc 7 4,089 May-11-2022, 02:23 PM
Last Post: menator01
  [solved] Basic question on list matchiing paul18fr 7 1,936 May-02-2022, 01:03 PM
Last Post: DeaD_EyE
  How to check if a list is in another list finndude 4 1,874 Jan-17-2022, 05:04 PM
Last Post: bowlofred
  [solved] Sort list paul18fr 5 2,944 Aug-18-2021, 06:34 AM
Last Post: naughtyCat
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,556 Aug-12-2021, 04:25 PM
Last Post: palladium

Forum Jump:

User Panel Messages

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