Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:31:58+00:00 2026-06-17T23:31:58+00:00

I am trying to have a queue using deque in python. The error I

  • 0

I am trying to have a queue using deque in python.

The error I keep getting is index out of range

perf_his[b][c] = 0

IndexError: deque index out of range

Here is a small prototype of the code that I implemented.

import collections

apps = [1,2,3]
num_thrs = len(apps)
perf_his = []
for a in range(num_thrs):
 perf_his += [collections.deque(maxlen=1)]

for b in range(num_thrs):
 for c in range(0, 1):
  perf_his[b][c] = 0

Inorder to check if I did understand deque correctly, I implemented this code:

#!/usr/bin/env python

from collections import deque

something = ["foo","bar","baz"]
output = []
diff = 0

d = deque()

for i in something:
    d.append(i)
    print("-> %s" % i)

for i in xrange(len(d)):
    print(d[i])
    output.append(d[i])

for i in xrange(len(something)):
    if output[i] != something[i]:
        diff += 1

print(something,output,diff)

I’ve been trying to fix the error in like 2 days, I don’t seem to understand the problem.
can someone please shed some light?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:31:59+00:00Added an answer on June 17, 2026 at 11:31 pm

    In your first bit of code, you never append() to the deque, and thus it never has an element “0”, and thus you aren’t allowed to assign to it. Setting maxlen doesn’t create elements, it just limits how many elements can be present later on.

    What you probably want instead is this:

    for a in range(num_thrs):
      perf_his += [collections.deque()]
    
    for b in range(num_thrs):
      for c in range(0, 1):
        perf_his[b].append(0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error when trying to create a message on a queue
I'm trying to create simply connect with ActiveMQ using JNDI. I have: Queue named
I'm getting an weird error using queues/multiprocessing. I basically have a function that takes
Here is code in which I am trying to implement a queue using linked
Here is what I am trying to accomplish by using NServiceBus. I have a
Trying to have my PHP script return some SQL table queries. Here's my script
I am currently trying to write a concurrent queue, but I have some segfaults
I'm trying to create a two sided queue with c++. I'm using Visual Studio
I am building a website using Redis as queue/messaging store. What I am trying
I have a WebSphere MQ Queue Manager with transmission queue defined and I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.