On 05/01/15 17:38, shweta kaushik wrote:
list = [[1,2,3,4,5],[2,3,4,4,6],[3,4,5,4,6],[1,4,5,4,8]]
for sublist in list:
... if sublist[3] == 4:
... print sublist[3]
...
4
4
4
4
I want sublist[3] value when matched first time and don't want the value
for second match.
You need to break out of the for loop.
The command to do that is 'break'
Just add a break on a line after the print
statement
And also i want to return same sublist value i.e. sublist[3] and want to
get the value of sublist[3] in another file.
I'm not sure I understand what you mean there.
If you break out of the loop you can still access
your loop variable. But I'm not sure what you mean
by "get the value of sublist[3] in another file."
Do you want to read another file and compare
it to sublist[3]?
Or do you want to put the value of sublist[3]
into another file?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor