Python Forum
How would you (as an python expert) make this code more efficient/simple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How would you (as an python expert) make this code more efficient/simple
#1
Hi,

my question is quite simple: How would you make this piece of code more simple/efficient?

def draw_pattern_1(p,m):
    print(p, end=' ')
    print(m, end=' ') 
    print(m, end=' ')
    print(m, end=' ')
    print(m, end=' ')
    print(p, end=' ')
    print(m, end=' ')
    print(m, end=' ')
    print(m, end=' ')
    print(m, end=' ')
    print(p)


def draw_pattern_2(l):
    print(l, end='         ')
    print(l, end='         ')
    print(l)
    

    
def draw_grid(f_1,f_2,p,m,l):
    draw_pattern_1(p,m)
    draw_pattern_2(l)
    draw_pattern_2(l)
    draw_pattern_2(l)
    draw_pattern_2(l)
    draw_pattern_1(p,m)
    draw_pattern_2(l)
    draw_pattern_2(l)
    draw_pattern_2(l)
    draw_pattern_2(l)
    draw_pattern_1(p,m)

p=  "+"
m = "-"
l = "|"

draw_grid(draw_pattern_1,draw_pattern_2,p,m,l)
Output:
+ - - - - + - - - - + | | | | | | | | | | | | + - - - - + - - - - + | | | | | | | | | | | | + - - - - + - - - - +
Reply


Messages In This Thread
How would you (as an python expert) make this code more efficient/simple - by coder_sw99 - Feb-20-2022, 11:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple code not working properly tmv 2 476 Feb-28-2025, 09:27 PM
Last Post: deanhystad
  Implementing Efficient Event-Driven Programming in Python JasonGrant 1 530 Jan-31-2025, 04:06 PM
Last Post: deanhystad
  How can I make this code more efficient and process faster? steven_ximen 0 358 Dec-17-2024, 04:27 PM
Last Post: steven_ximen
  [pyparsing] How to make my simple parser fault tolerant medihack 0 832 May-14-2024, 04:52 PM
Last Post: medihack
  Help with simple code JacobSkinner 1 1,296 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  hi need help to make this code work correctly atulkul1985 5 1,868 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 1,227 Nov-07-2023, 04:32 PM
Last Post: snippsat
  newbie question - can't make code work tronic72 2 1,485 Oct-22-2023, 09:08 PM
Last Post: tronic72
  A more efficient code titanif 2 1,142 Oct-17-2023, 02:07 PM
Last Post: deanhystad
  Cleaning my code to make it more efficient BSDevo 13 3,548 Sep-27-2023, 10:39 PM
Last Post: BSDevo

Forum Jump:

User Panel Messages

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