0

I am pretty new in python! Here below i have a list of 5 different strings.

afilelistawarded = ['123,456,789,12345,Correct,67890','a123,b456,c789,d12345,Correct,e67890','f123,g456,h789,i12345,Correct,j67890','k123,l456,m789,n12345,Correct,o67890','p123,q456,r789,s12345,Correct,t67890']

for i1 in afilelistawarded:
    for i2 in (afilelistawarded[i1]):
      del ((afilelistawarded[i1])[0])
      del ((afilelistawarded[i1])[1])
      del ((afilelistawarded[i1])[2])
      del ((afilelistawarded[i1])[3])
      del ((afilelistawarded[i1])[5])

print afilelistawarded

I am trying to output the following:

 afilelistawarded=['Correct','Correct','Correct','Correct','Correct']

How do i remove the unwanted items and output the correct strings to the same list?

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Sam T
  • 77
  • 1
  • 7

3 Answers3

0

If you are sure the 'Correct' always appears at index=4, you can simply use :

afilelistawarded = ['123,456,789,12345,Correct,67890','a123,b456,c789,d12345,Correct,e67890','f123,g456,h789,i12345,Correct,j67890','k123,l456,m789,n12345,Correct,o67890','p123,q456,r789,s12345,Correct,t67890']

for i1 in afilelistawarded:
    print i1.split(",")[4]
Gautam
  • 1,862
  • 9
  • 16
0

This works for me:

>>> afilelistawarded = ['123,456,789,12345,Correct,67890','a123,b456,c789,d12345,Correct,e67890','f123,g456,h789,i12345,Correct,j67890','k123,l456,m789,n12345,Correct,o67890','p123,q456,r789,s12345,Correct,t67890']
>>> [i.split()[4] for i in afilelistawarded]
['Correct', 'Correct', 'Correct', 'Correct', 'Correct']
lenik
  • 23,228
  • 4
  • 34
  • 43
0

Here, This should work, if you are sure about the position of the 'correct' element.

ls = []
filelistawarded = ['123,456,789,12345,Correct,67890','a123,b456,c789,d12345,Correct,e67890','f123,g456,h789,i12345,Correct,j67890','k123,l456,m789,n12345,Correct,o67890','p123,q456,r789,s12345,Correct,t67890']

for item in afilelistawarded:
           ls.append(item.split(',')[4])
Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34