-1

I want to be able to print the 3rd number with in a list of sublist. I am okay with interacting through the list and sublist, but unsure with how i can print the 3rd number of each sublist. for example [[1,2,3,4][1,2,3,4][,1,2,3,4][1,2,3,4]] i was to achieve 3,3,3,3

I have manage this so far, being able to print out all numbers with the sublists

def Contact(num):<br/>
    for i in range(len(num)):<br/>
        for j in range(len(num[i])):<br/>
                print(num[i][j])

Contact([[1,2,3,4][1,2,3,4][,1,2,3,4][1,2,3,4]])
shivsn
  • 7,680
  • 1
  • 26
  • 33

2 Answers2

2
def contact(num):
    for sub_list in num:
        print sub_list[2]
0

try this here http://pythonfiddle.com/

def Contact( mainlist ):
    for sublist in mainlist:
        print( sublist[2] ) # accessing third element

Contact( [ [ 1,2,3,4 ], [ 1,2,3,4 ], [ 1,2,3,4 ], [ 1,2,3,4 ] ] )
Priyesh Kumar
  • 2,837
  • 1
  • 15
  • 29