[Tutor] How to get value of sublist as return to verify in other file

Steven D'Aprano steve at pearwood.info
Tue Jan 6 01:28:14 CET 2015


On Mon, Jan 05, 2015 at 11:08:16PM +0530, shweta kaushik wrote:
> Hi All,
> 
> I need help for list.
> 
> I am having one list of list
> 
> list =  [[1, 2, 3, 4], [1, 5, 9, 11,5], [1, 6, 7, 2]]
> 
> In this list i am getting sublist value as shown below:
> 
> >>> 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.

I do not understand what you are asking. Do you mean that you only want 
to match once?


py> list_of_lists = [[1, 2, 3, 4], [4, 5, 6, 7], [5, 2, 1, 4]]
py> for sublist in list_of_lists:
...     if sublist[3] == 4:
...             print(sublist)
...             break
...
[1, 2, 3, 4]
py> 



> 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 am sorry, I have no idea what you are asking. Can you show some sample 
code and data that demonstrates what you are trying to do?


-- 
Steve


More information about the Tutor mailing list