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 7871353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:52:43+00:00 2026-06-03T01:52:43+00:00

The python data strcutures page http://docs.python.org/tutorial/datastructures.html says It is also possible to use a

  • 0

The python data strcutures page http://docs.python.org/tutorial/datastructures.html says

It is also possible to use a list as a queue, where the first element added is the first element retrieved (“first-in, first-out”); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one).

I can understand why doing inserts at the front of the list would take be inefficient. But why does it say that popping the head / beginning of a list is slow? No shifting is required while doing a pop operation at the list -head right?

  • 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-03T01:52:45+00:00Added an answer on June 3, 2026 at 1:52 am

    No shifting is required while doing a pop operation at the list -head right?

    Think of a list as an array of references, where the first element of the list is always at array position zero. When you pop the first element of the list, you have to shift all the reference to the left by one position.

    One could imagine alternative implementations, where popping the front of the list would be cheap (e.g. deque-style). I think we can trust the Python docs on this one, and assume that this is not how the built-in list class is implemented.

    If you need efficient removals from the front of the container, use collections.deque:

    Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about the dictionary in python, in the reference page: http://docs.python.org/tutorial/datastructures.html#dictionaries
I'm trying to scrape the data off a web page using the python Windmill
Possible Duplicate: How do you split a list into evenly sized chunks in Python?
I have a python data-structure as follows: A = [{'abc': 'kjkjl'},{'abc': 'hjhjh'},{'abc': '78787'}] How
I send binary data over websocket from python server: data = struct.pack('!BI', 2, 1)
What chances do I have to instantiate, keep and serialize/deserialize to/from binary data Python
Are there any python libraries for data trees? I mean a tree as a
I have developed a python C-extension that receives data from python and compute some
I'd like to store some data in Python in a similar form to a
I am considering moving from Matlab to Python/numpy for data analysis and numerical simulations.

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.