Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ignoring a list item
#1
Hi all!
I need a bit of help ignoring a list item, I have a list of names with a "Y" at then end of each name and I want to ignore names without a "Y", my code is below:

from time import strftime # import time
print("Report date: " + strftime("%d/%m/%Y")) #Prints clock time

with open("confPack.txt", "r") as confPack: # open file as confpack
    cPack = confPack.read().splitlines() # create cpak variable

with open("employees.txt") as fp:
    for line in fp:
        values = line.strip().split(",")
        surname = values[0]
        firstName = values[1]

        # is the last value not a Y (meaning no Y's)

        # if that's false, meaning there is a Y, is the one before it a Y too
        if values[-1] != 'Y':
            print(" did not attend ")
        elif values[-2] == 'Y':
            packs = print(cPack[1])
        else:
            packs = print(cPack[0])
        print(f"Attendee: {surname}, {firstName}: {packs}")
Thanks in advance!
Reply


Messages In This Thread
Ignoring a list item - by hank4eva - Aug-17-2020, 12:27 AM
RE: Ignoring a list item - by deanhystad - Aug-17-2020, 02:17 AM
RE: Ignoring a list item - by perfringo - Aug-17-2020, 08:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  WARNING: Ignoring invalid distribution kucingkembar 1 24,500 Sep-02-2022, 06:49 AM
Last Post: snippsat
Question Finding string in list item jesse68 8 1,864 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  how to easily create a list of already existing item CompleteNewb 15 3,527 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,692 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  count item in list korenron 8 3,443 Aug-18-2021, 06:40 AM
Last Post: naughtyCat
  Ignoring errors when using robjects. Rav013 3 3,083 May-04-2021, 09:05 PM
Last Post: Gribouillis
  Time.sleep: stop appending item to the list if time is early quest 0 1,872 Apr-13-2021, 11:44 AM
Last Post: quest
  How to run a pytest test for each item in a list arielma 0 2,368 Jan-06-2021, 10:40 PM
Last Post: arielma
  How do I add a number to every item in a list? john316 2 1,969 Oct-28-2020, 05:29 PM
Last Post: deanhystad
  Select correct item from list for subprocess command pythonnewbie138 6 3,292 Jul-24-2020, 09:09 PM
Last Post: pythonnewbie138

Forum Jump:

User Panel Messages

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