I have list :
l = ['dataset/Frames_Sentence_Level/are you free today/5/free (3) 22.jpg','dataset/Frames_Sentence_Level/are you free today/6/free (3) 24.jpg','dataset/Frames_Sentence_Level/are you free today/7/free (3) 23.jpg']
Here I need output as the list consists of 5,6,7 from the list, that is
[5,6,7]
So for that I tried like below,
s= []
for i in l:
e = i.split('/')`
s = e[3]
print(s)
when I print s inside the for loop, I am getting the output but if I print outside the loop the output is just 7. Please help me out
s.append(e[3])? you need to add items to the list, not reassign it every iteration.e[3] == 7, sos = e[3]also makess == 7. If you want to keep it a list append not reassign.