Python Forum
A simple script - looking for feedback
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A simple script - looking for feedback
#2
I'll start by listing a few problems I see with the code:
  • Initializing all of those variables at the start of your code is not needed
  • The global statement is very rarely a good idea; pass arguments to functions and return values instead of modifying globals and appending to lists, and if you need state, use classes
  • You should never write loops over the indices of a list if you actually want elements. Instead of:
    for i in range (0,100):
        if dblist[i] == 1:
    use
    for number in dblist:
        if number == 1:
    You can take a look at this talk to learn more about python's loops.
  • A function should only do one thing. Your random100() function creates a list of numbers, finds streaks in it, and returns the longest ones. Splitting it into a few simpler functions would make the code more readable and easier to test and maintain.

All that said, what's really important is you wrote some code that does what you want.
That, along with reading others people's code, is the best way to improve.
Reply


Messages In This Thread
RE: A simple script - looking for feedback - by stranac - Feb-20-2018, 09:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Python script, path not defined dubinaone 3 2,794 Nov-06-2021, 07:36 PM
Last Post: snippsat
  Need help creating a simple script Nonameface 12 4,818 Jul-14-2020, 02:10 PM
Last Post: BitPythoner
  Simple text to binary python script gmills13 2 2,889 Feb-04-2020, 08:44 PM
Last Post: snippsat
  Made a simple script for android (really simple) but it is not running anddontyoucomebacknomore 2 2,454 Mar-06-2019, 12:19 AM
Last Post: anddontyoucomebacknomore
  Feedback and help tomX 13 5,711 Dec-31-2018, 11:00 PM
Last Post: Larz60+
  Simple script that seems to misbehave? Nwb 1 2,407 Jun-10-2018, 05:30 AM
Last Post: Nwb
  First time with Python.. need help with simple script shakir_abdul_ahad 7 5,735 May-06-2018, 09:28 AM
Last Post: killerrex
  help with a simple script juanb007 4 3,798 May-01-2018, 08:06 PM
Last Post: ThiefOfTime
  Simple script writted by a dumb dude, myself mm14ag 2 2,874 Apr-28-2018, 11:48 AM
Last Post: mm14ag
  Need help with a simple AHK script Stabu 0 2,149 Feb-24-2018, 08:27 PM
Last Post: Stabu

Forum Jump:

User Panel Messages

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