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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:52:36+00:00 2026-06-11T19:52:36+00:00

I am writing a simple collection abstraction in python using Bisect function. The problem

  • 0

I am writing a simple collection abstraction in python using Bisect function. The problem here is that when I use insort function to add the data in the list, the function returns None. But when i use BISECT.BISECT(lst,ele), the function returns the value which would be the index of the list where the element could be inserted if desired.

# Python program to implement collection abstraction
# using Bisect Algorithm
# The program would add an element into the SORTED LIST"
# which would be the input
# The program would test whether the element is in the collection
# And also, to return the element of the collection if it is there

from bisect import bisect
from bisect import insort_right

the_list = []

def add(lst,ele):

    return insort_right(lst,ele)

#def test(lst,ele)

#def remove(lst,ele):


print("Enter the size of the list:")
N = int(input())

for x in range(N):

    x = input("")    
    the_list.append(x)
    the_list.sort()

print(the_list)

print("Enter the element to be added in the list")
element = input("")

add_element = add(the_list,element)
print("The element is added in collection at location:", add_element)
  • 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-11T19:52:38+00:00Added an answer on June 11, 2026 at 7:52 pm

    insort doesn’t return a value because it alters the list itself. Generally, Python functions that use side effects this way don’t return values. If you want to return the modified list from add, do this:

    def add(lst, ele):
        insort_right(lst, ele)
        return lst
    

    But there’s really no point in doing so, since the returned list is the same as the list that was passed in. The calling context already has access to that list, so there’s no need to return it, and doing so is a bit unidiomatic.

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

Sidebar

Related Questions

As I'm a novice, I started learning python by writing simple programs using python
I'm having a simple problem when it comes to writing up typeclasses that inherit
I am writing simple parallel program in C++ using OpenMP. I am working on
I am writing simple site that requires users and profiles to be handled. The
I'm writing simple filter in Android and want to use ExpandableListAdapter with check boxes.
I'm writing simple GUI using wxPyhon and faced some problems. My application does simple
I'm writing a simple C# program and want to use an SQL server to
I'm writing a small software application that needs to serve as a simple planning
I'm writing a simple game in XNA and I've faced a problem with delegates.
I'm writing a tool that will generate HTML based on JSON data, and puts

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.