Hello again.
How can i limit my list indexes?
I want my list to take only 3 indexes for example.
Niloofar24
15
Posting Whiz
Recommended Answers
Jump to PostNot sure why you want to do this, but one way is to build a ringbuffer ...
import collections def ringbuffer_append(item, dq=collections.deque(maxlen=3)): ''' mimics a ringbuffer of length 3 you can change maxlen to your needs ''' dq.append(item) return list(dq) # testing mylist = ringbuffer_append('red') print(mylist) mylist …
Jump to PostThis will do, create a custom list append ...
def list_append(item, tlist=[], limit=3): ''' append max limit items to a list list cannot exceed given limit size ''' if len(tlist) < limit: tlist.append(item) return tlist # testing mylist = list_append('red') print(mylist) mylist = list_append('green') print(mylist) mylist = …
All 7 Replies
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Niloofar24
15
Posting Whiz
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Niloofar24
15
Posting Whiz
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.