Shaun Gerber
Shaun Gerber

Reputation: 19

How to make a smaller list of tuples from a large list of tuples?

I have a large list with about 50 or 60 tuples. In the form:

a=[('a', 50), ('b', 46), ('c', 41), ('d', 35) ...]

I want a new list with only the first 20 tuples in the list. Like:

b=[('a', 50), ('b', 46), ('c', 41), ('d', 35) ... ,('aa', 10)]

Upvotes: 0

Views: 218

Answers (1)

David Robinson
David Robinson

Reputation: 78620

This can be done using list slicing:

b = a[:20]

Upvotes: 3

Related Questions