Is it possible to fix the size of a list in python so that if the list contains more than that it'll throw an errorFinding the index of an item given a list containing it in PythonHow do I parse a string to a float or int in Python?How do I determine the size of an object in Python?How do I sort a dictionary by value?How to split a string into a list?Split Strings into words with multiple word boundary delimitersHow to read a file line-by-line into a list?Create List of Single Item Repeated n Times in PythonWhy is reading lines from stdin much slower in C++ than Python?Get list from pandas DataFrame column headers

How much RAM could one put in a typical 80386 setup?

What is the offset in a seaplane's hull?

How do I create uniquely male characters?

How to re-create Edward Weson's Pepper No. 30?

If Manufacturer spice model and Datasheet give different values which should I use?

What is the command to reset a PC without deleting any files

Should I join office cleaning event for free?

A Journey Through Space and Time

Why can't I see bouncing of a switch on an oscilloscope?

Is it possible to make sharp wind that can cut stuff from afar?

Type 1 Error & Type 2 Error's pregnancy test analogy: is it legit?

The use of multiple foreign keys on same column in SQL Server

A function which translates a sentence to title-case

How can I fix this gap between bookcases I made?

Prevent a directory in /tmp from being deleted

Why is the design of haulage companies so “special”?

Is the language <p,n> belongs to NP class?

How to report a triplet of septets in NMR tabulation?

"which" command doesn't work / path of Safari?

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

The magic money tree problem

How long does it take to type this?

Is it possible to do 50 km distance without any previous training?

If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?



Is it possible to fix the size of a list in python so that if the list contains more than that it'll throw an error


Finding the index of an item given a list containing it in PythonHow do I parse a string to a float or int in Python?How do I determine the size of an object in Python?How do I sort a dictionary by value?How to split a string into a list?Split Strings into words with multiple word boundary delimitersHow to read a file line-by-line into a list?Create List of Single Item Repeated n Times in PythonWhy is reading lines from stdin much slower in C++ than Python?Get list from pandas DataFrame column headers






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















n = int(input()) #fixed length
l = input().split()


the list that I want should be given as one line input so I dont know how range will help??










share|improve this question



















  • 1





    Are you editing the data at all? If not just use a tuple because it is immutable!

    – Reedinationer
    Mar 9 at 2:08











  • Are you by chance looking for the maxsplit argument to split()?

    – Daniel Pryden
    Mar 9 at 2:20






  • 1





    Sounds like an XY problem. What are you trying to solve with this?

    – Klaus D.
    Mar 9 at 2:27

















0















n = int(input()) #fixed length
l = input().split()


the list that I want should be given as one line input so I dont know how range will help??










share|improve this question



















  • 1





    Are you editing the data at all? If not just use a tuple because it is immutable!

    – Reedinationer
    Mar 9 at 2:08











  • Are you by chance looking for the maxsplit argument to split()?

    – Daniel Pryden
    Mar 9 at 2:20






  • 1





    Sounds like an XY problem. What are you trying to solve with this?

    – Klaus D.
    Mar 9 at 2:27













0












0








0








n = int(input()) #fixed length
l = input().split()


the list that I want should be given as one line input so I dont know how range will help??










share|improve this question
















n = int(input()) #fixed length
l = input().split()


the list that I want should be given as one line input so I dont know how range will help??







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 3:28









Magnus Melwin

77211122




77211122










asked Mar 9 at 2:06









LOWERCASELOWERCASE

81




81







  • 1





    Are you editing the data at all? If not just use a tuple because it is immutable!

    – Reedinationer
    Mar 9 at 2:08











  • Are you by chance looking for the maxsplit argument to split()?

    – Daniel Pryden
    Mar 9 at 2:20






  • 1





    Sounds like an XY problem. What are you trying to solve with this?

    – Klaus D.
    Mar 9 at 2:27












  • 1





    Are you editing the data at all? If not just use a tuple because it is immutable!

    – Reedinationer
    Mar 9 at 2:08











  • Are you by chance looking for the maxsplit argument to split()?

    – Daniel Pryden
    Mar 9 at 2:20






  • 1





    Sounds like an XY problem. What are you trying to solve with this?

    – Klaus D.
    Mar 9 at 2:27







1




1





Are you editing the data at all? If not just use a tuple because it is immutable!

– Reedinationer
Mar 9 at 2:08





Are you editing the data at all? If not just use a tuple because it is immutable!

– Reedinationer
Mar 9 at 2:08













Are you by chance looking for the maxsplit argument to split()?

– Daniel Pryden
Mar 9 at 2:20





Are you by chance looking for the maxsplit argument to split()?

– Daniel Pryden
Mar 9 at 2:20




1




1





Sounds like an XY problem. What are you trying to solve with this?

– Klaus D.
Mar 9 at 2:27





Sounds like an XY problem. What are you trying to solve with this?

– Klaus D.
Mar 9 at 2:27












2 Answers
2






active

oldest

votes


















1














Check the length using len() and raise the error.



if len(l)>n:
raise Exception('Please give only inputs'.format(n))





share|improve this answer






























    1














    You can use len to determine the size of a list or tuple.



    if len(l) > n: # assuming n is the max size 
    print("List too large")





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073304%2fis-it-possible-to-fix-the-size-of-a-list-in-python-so-that-if-the-list-contains%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Check the length using len() and raise the error.



      if len(l)>n:
      raise Exception('Please give only inputs'.format(n))





      share|improve this answer



























        1














        Check the length using len() and raise the error.



        if len(l)>n:
        raise Exception('Please give only inputs'.format(n))





        share|improve this answer

























          1












          1








          1







          Check the length using len() and raise the error.



          if len(l)>n:
          raise Exception('Please give only inputs'.format(n))





          share|improve this answer













          Check the length using len() and raise the error.



          if len(l)>n:
          raise Exception('Please give only inputs'.format(n))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 9 at 2:18









          sambasiva raosambasiva rao

          1386




          1386























              1














              You can use len to determine the size of a list or tuple.



              if len(l) > n: # assuming n is the max size 
              print("List too large")





              share|improve this answer



























                1














                You can use len to determine the size of a list or tuple.



                if len(l) > n: # assuming n is the max size 
                print("List too large")





                share|improve this answer

























                  1












                  1








                  1







                  You can use len to determine the size of a list or tuple.



                  if len(l) > n: # assuming n is the max size 
                  print("List too large")





                  share|improve this answer













                  You can use len to determine the size of a list or tuple.



                  if len(l) > n: # assuming n is the max size 
                  print("List too large")






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 9 at 2:15









                  whirishwhirish

                  303114




                  303114



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073304%2fis-it-possible-to-fix-the-size-of-a-list-in-python-so-that-if-the-list-contains%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme