Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in Pycharm
#4
Quote:Yes, I want the sequence {9, 8, 7, 6, 5, 4, 3, 2, 1}. Instead of coding for it by looping down from 9 to 1 I should just create the list my_list = [9, 8, 7, 6, 5, 4, 3, 2, 1]
Would my_list always be [9, 8, 7, 6, 5, 4, 3, 2, 1]? If so, that would be a good way to build the list. If you want to build a list where the starting and ending numbers are not always the same, using range() is a good way to make a list.
my_list = list(range(9, 0, -1))
Save append() for when there is some processing involved when adding items to a list. Be leery about using insert as it can be complicated to insert multiple values int a list (unless you are always inserting at the front). I usually make a new list instead of inserting items into an existing list. If you really want to use insert, insert the last value first and work your way back to the first value. That way you are inserting into the part of the list that has not been moved by other inserts.
Hudjefa likes this post
Reply


Messages In This Thread
Error in Pycharm - by Hudjefa - Oct-02-2024, 08:34 AM
RE: Error in Pycharm - by deanhystad - Oct-02-2024, 09:13 PM
RE: Error in Pycharm - by Hudjefa - Oct-09-2024, 02:45 AM
RE: Error in Pycharm - by deanhystad - Oct-09-2024, 08:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 2,613 Sep-09-2024, 08:03 AM
Last Post: pinkang
  Pycharm error zuri 1 1,167 Nov-01-2023, 03:38 PM
Last Post: deanhystad
  PyCharm Error? coder_sw99 4 3,029 Sep-24-2021, 06:16 PM
Last Post: Yoriz
  Keep getting Session management error when running imshow in pycharm pace 0 2,966 Mar-25-2021, 10:06 AM
Last Post: pace
  REGEX Install Error in PyCharm charlesauspicks 1 3,620 May-14-2020, 08:10 PM
Last Post: buran
  Traceback error in PyCharm but not in other IDEs? devansing 7 8,947 Mar-05-2020, 11:27 AM
Last Post: buran
  Error in importing package in pycharm fullstop 0 2,915 Dec-12-2019, 04:03 PM
Last Post: fullstop
  can't assign to literal error in pycharm ryder5227 2 3,936 Oct-07-2019, 08:57 PM
Last Post: Bmart6969
  Weird error in pycharm TheRedFedora 1 3,416 Mar-11-2018, 09:01 PM
Last Post: Larz60+
  python turtle module in pycharm error sajley 2 14,415 Dec-12-2016, 08:52 PM
Last Post: sajley

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020