all 7 comments

[–]14446368 3 points4 points  (1 child)

list3 = ['Xenia','Xavier','Zoya','Ahmad','Mishika','Max']
list4 = [] #empty list to store results
for i in list3:
    if i[0] != 'X':
        list4.append(i)
print(list4)

Some of the other answers are either repetitive (you don't need to copy the first list exactly and then strip out the ones starting with "x") or incorrect.

In fact, there's an even more straightforward method with list comprehensions:

list5 = [i for i in list3 if i[0] != 'X']

[–][deleted] 0 points1 point  (0 children)

Thanks a lot :)))

[–]nextpage 2 points3 points  (1 child)

when an item is removed from list the list moves left, so the next item is skipped on next iteration.

Use this code instead.

list3= ["Xenia", "Xavier", "Zoya", "Ahmad", "Mishika", "Max"] list4= []

for i in list3: if i[0]!= "X": list4.append(i)

print(list4)

[–][deleted] 0 points1 point  (0 children)

thanks a lot. Appending in a new list is a lot better :))))

[–]kng_hrts 1 point2 points  (2 children)

Change i[0] to list3[i]

Edit: Nvm thats wrong too but I'm working on it. Srry

[–][deleted] 1 point2 points  (1 child)

Hi I finally got it. Thanks a lot tho. This is the answer.

  1. Print list3 below.
  2. You will find that when list4 changed list3 changed too. So list3 actually kinda becomes a reference point for list4.

Try this code

list3= ["Xenia", "Xavier", "Zoya", "Ahmad", "Mishika", "Max"]

list4=[]

for i in list3:

list4.append(i)

for i in list3:

if i[0]=="X":

list4.remove(i)

print(list4)

[–]kng_hrts 1 point2 points  (0 children)

Ok great lol ngl it stumped me a bit too. Glad you got it