[Tutor] How to get value of sublist as return to verify in other file
alan.gauld at btinternet.com
Tue Jan 6 01:37:21 CET 2015
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 == 4:
> ... print sublist
> I want sublist 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
> And also i want to return same sublist value i.e. sublist and want to
> get the value of sublist 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 in another file."
Do you want to read another file and compare
it to sublist?
Or do you want to put the value of sublist
into another file?
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor