So my listname is men =[]

How can i print just the 10 first elements of the list? It contains 15...
And it's a matrix...

I thought about making a while-loop while i > 9: but it didn't work.

Can anybody help me please? :)

for gender in men:
            print gender[0] + " " + gender[1] + "\t""\t"" " + gender[2] + "\t" + 
            gender[3] + "\t" , gender[10]
Member Avatar for masterofpuppets

hi,
you could do something like this:

men = [ [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ], [ 7 ], [ 8 ], [ 9 ], [ 10 ], [ 11 ], [ 12 ], [ 13 ], [ 14 ], [ 15 ] ]
for gender in men[ :10 ]:
	print gender

# Output:
"""[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]"""

I'm not sure whether the format of the list I'm using is the same as the one you specified, so pls. correct me if this is not right.

hope this helps :)

Sorry, masterofpuppets already suggested slicing the list.

thnx alot guys! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.