Armin
Armin

Reputation: 3

Exclude or not including item in python

I'm a learning programmer and i'm doing a challenge but i'm stuck the challenge is this:

Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".

And my code is this:

def loopy(items):
# Code goes here
if item == 'a':
    continue
elif:
    break
for item in times:
    print(item)

it wont pass. please help me i'm stuck and don't know how to do it.

Upvotes: 0

Views: 130

Answers (2)

rnso
rnso

Reputation: 24623

You can use following code to convert items from ["abc", "xyz"] to ['a', 'x'] :

items = list(map(lambda x:x[0], items))

Then you can check each item in a loop and see if it equals 'a'.

Upvotes: 0

Treyten Carey
Treyten Carey

Reputation: 661

RomamPerekhrest's comment is correct, but I believe this might be a better place to start for learning programmers.

# for all items in the list, get the single item
for item in items:
    # if the item at index 0 is not 'a'
    if item[0] != 'a':
        # print the item that doesn't start with 'a'
        print(item)

Upvotes: 1

Related Questions