current position：Home>[entertainment] Python simple implementation of fixed length queue
[entertainment] Python simple implementation of fixed length queue
2022-07-19 08:21:33【qq_ seven hundred and four million four hundred and forty-six t】
Please give priority to real use, such as collections.deque Such method libraries , Because the efficiency of what I wrote is too low , by comparison .
class FLenList(object): def __init__(self, length: int): assert isinstance(length, int) and length > 0, " Please give me an integer greater than zero to specify the length " self.len = length self.data = [None] * self.len self.hand = 0 self.handleft = -1 def append(self, obj): if self.data[self.handleft] is not None: self.handleft = (self.handleft + 1) % self.len self.data[self.hand] = obj self.hand = (self.hand + 1) % self.len def appendleft(self, obj): if self.data[self.hand] is not None: self.hand = (self.hand - 1) % self.len self.data[self.handleft] = obj self.handleft = (self.handleft - 1) % self.len def __len__(self): return self.len def get(self): ret = self.data[self.hand:] ret.extend(self.data[:self.hand]) return ret
Want to add the effect when the length does not reach the specified maximum length , Don't write if you feel troublesome , I can't use it anyway
author[qq_ seven hundred and four million four hundred and forty-six t],Please bring the original link to reprint, thank you.
The sidebar is recommended
- SARFT: illegal and immoral artists are forbidden to appear in TV dramas
- It's not just friends that reunites
- Finally, there is a movie. Let's say goodbye to Wu Mengda on the screen
- "Never forget the farm" after a visit, everyone can find the courage to face aging
- NFT insider 65: South Korean entertainment giant CJ ENM has reached a cooperation with the sandbox, and YGG has established a subdao in the Brazilian community
- "Mom! I realized Gu Ailing's happiness... Ah - help, help!"
- Gaya decrypts the front and back scenes of the 2022 Oriental satellite TV Spring Festival Gala
- Wu Yue sent an angry report! Rumor father said that she was abandoned by her boyfriend and was still babbled after 16 years of separation
- Stars appear in the rehearsal of CCTV Lantern Festival party, and Nigel Maiti will pick the beam again? Wan Qian and Song Yi are well dressed
- Official propaganda "sugar"! 2022 "tiger adds wings" small palm Lantern Festival comes, zero consumption can also win awards
guess what you like
The Spring Festival has achieved their "ten billion" miracle!
February 14th! "Zhiyin" is about to resume its flight
No emo on Valentine's Day| Ticket delivery
Rizhao newborn's popular name comes out! The three names with the most duplicate names are
The ice dance drama we are one starring Pang Qing and Tong Jian, the world champion, premiered successfully at Beijing overpass Art Center
Wang Lili, who did not participate, became one of the hottest people in this winter Olympics
Zhang Yimou, who is in his seventies, simply "changed the world" with the glory of the Winter Olympics
Bao Wenjing's family went shopping in the supermarket. The dumplings were exquisite and changed a lot. Their height was close to Bao Bell's waist
Many times on CCTV Spring Festival Gala! Reveal the secret of lucky lion
Experts decode 2022 Spring Festival: presenting a new look of Chinese films
- The animated film "pillow knife song: a journey to the earth" was highly praised, and the soundtrack was pleasantly online
- This Sunday evening, there will be a festive event in Nanfeng City, Hongqiao... | aishenhuo warms the heart
- "Don't forget I love you" Naza and Liu Yihao perform the most beautiful confession
- From Ling Na BEI'ER to Bing Dwen Dwen, from Liu Xiang to Gu ailing
- You are so beautiful! Anne Hathaway appeared on Broadway to support uncle wolf's musical
- The grand prize was unveiled, and Jinnan court was on the list
- It's half time, come and look around!
- Cao Jingxing, a media man, died at the age of 75 and was once called "news radar"
- Veterans will always be young, dreams will always shine | Beijing to the future focuses on the Chinese army that will never give up
- Dongxi asked | how much do you know about "Baba niangya" in the TV series "little niangya"?
- The audience is abandoning the cinema?
- The online drama "Hello, Captain" is about to start a new chapter of civil aviation drama
- Exclusive dialogue -- Peng Xiaoran: pay tribute to the Winter Olympic athletes, who are familiar with northeast cuisine
- "Our hot life" Chen Xiaochun's first experience of legal aid Zhang Qi's visit to women's prison tears collapse
- Bloom the beauty of Winter Olympics with "the name of ice and snow"
- Naza basks in the photo of Lord snow eagle, holding flowers and smiling sweetly
- Friends returns: why is this play so happy? Because it is the portrayal of our ideal life
- Happy thousands of smiles show the new year's new atmosphere
- Retro beauty! Zhang Zifeng's self portrait of his face is super cute to the camera
- After 12 years as a supporting actor, he was almost expelled from happy fried dough twist. Now Wei Xiang is successful as the male number one?
- Ten male stars of "drama dishonor": if there are more such actors, the audience will not be poisoned by the rotten film
- From the king of TV viewing to the queen of turntable, why is Xie Na, the "first sister of satellite TV", less and less likeable
- On the thirty six strategies of Chinese traditional art of war from "sniper"
- Chen Suping: years flow, keeping the miss of Gu Yuezhen and the soul of "hard work"
- Screenwriter Wang Hailing talks about behind the scenes: not all life should be open, and "the world" can comfort ordinary people
- Rebirth entertainment is developing a new single FPS and the same universe as apex hero
- Rebirth entertainment may develop a new single FPS game based on the universe of apex heroes
- Farewell film curtain call performance, giant screen cinema of China Science and Technology Museum will start digital transformation
- Detective 7 pays attention to campus bullying, judges' panel online popularization of legal knowledge
- Li Fei directed the warm comedy "Nobel's gift" and started it. Zhang Benyu, Han Haolin, pan Binlong explored the true meaning of family affection
- Female star data exposure, Liu Yifei is the most popular, and Yang Mi's baby is not in the top three
- "I want to go to your world and love you" released the theme song MV Jiao Maiqi's warm singing of the theme song of the premiere film
- 40% red line! SARFT continues to regulate sky high film remuneration
- Essence of SIFF film school | Dennis Villeneuve: pursuing poetry and intuition in the dunes of film
- Liu Yu, a member of into1, took a funny group photo for his teammate Bo Yuan's birthday
- Workplace gongdou? Fashion circle melon collection? Yuan Yongyi, Song Jia, song Zuer's new play "dress up" is a bit of a hit
- The costume action movie "Daming flying fish suit" appeared on the international stage as a dark horse
- What is the experience of walking on the red carpet in school uniforms
- Urban workplace drama "dress up" is popular, and the old depression points to the rules of workplace survival
- Simple and thick epic masterpiece | after the view of CCTV reality TV series "human world"