Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

example of a bad code

    game=[[1,1,1,1,1,1,1],
         [1,'A',1,1,0,0,1],
         [1,0,0,0,0,1,1],
         [1,0,0,1,1,1,1],
         [1,1,0,0,0,'B',1],
         [1,1,1,1,1,1,1]]
    rows=len(game)
    cols=len(game[0])
    graph={}
    for i in range(1,rows-1):
       for i in range(1,rows-1):
          if(game[i][j]!=1):
          adj=[]
          for ele in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
               if game[ele[0]][ele[1]] == 0 or game[ele[0]][ele[1]]=='B' :
                       adj.append((ele[0],ele[1]))
          graph[(i,j)]=adj
    print(graph)

    {(1, 1): [(2, 1)],
    (1, 4): [(2, 4), (1, 5)],
    (1, 5): [(1, 4)],
    (2, 1): [(3, 1), (2, 2)],
    (2, 2): [(3, 2), (2, 1), (2, 3)],
    (2, 3): [(2, 2), (2, 4)],
    (2, 4): [(1, 4), (2, 3)],
    (3, 1): [(2, 1), (3, 2)],
    (3, 2): [(2, 2), (4, 2), (3, 1)],
    (4, 2): [(3, 2), (4, 3)],
    (4, 3): [(4, 2), (4, 4)],
    (4, 4): [(4, 3), (4, 5)],
    (4, 5): [(4, 4)]}
Comment

PREVIOUS NEXT
Code Example
Python :: qq plot using seaborn 
Python :: aiml python install 
Python :: legend matplotlib twinx 
Python :: fibonacci formula python 
Python :: fibonacci series recursive python 
Python :: program fibonacci series number in python 
Python :: JET token authentication in Django UTC 
Python :: how to check if a column exists before alter the table 
Python :: Left fill with zeros 
Python :: python min function time complexity 
Python :: how to do downsampling in python 
Python :: list all subdirectories up to a level 
Python :: sql o que é 
Python :: pytorch rolling window 
Python :: pandas replace duplicates unique identifier 
Python :: how to print multiple lines in one line python 
Python :: the webpage at http://127.0.0.1:8000/ might be temporarily down or it may have moved permanently to a new web address. django 
Python :: get all non numeric columns pandas 
Python :: compute difference in dates after groupby 
Python :: # swap variables 
Python :: quadkey calculator 
Python :: pandas dataframe how to store 
Python :: pop tkinter to the front of the screen 
Python :: Python Anagram Using sorted() function 
Python :: Errors while using os.makedirs() method 
Python :: faceModel = "opencv_face_detector_uint8.pb" 
Python :: django updateview not saving 
Python :: automate ms word with python 
Python :: How to srape all links from a website in python 
Python :: python antigravity 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =