D
D
Danya072020-08-11 19:28:24
Python
Danya07, 2020-08-11 19:28:24

How to make code easier python?

How to make the code simpler and more readable?
An array can be three dimensional

a = 
for x in range(10):
  a[0][0] += 1
  for i in range(len(a)-1):
    for y in range(len(a[i])-1):
      if a[i][y] > 1:
        a[i][y] = 0
        a[i][y+1] += 1
    if a[i][len(a[i])-1] > 1:
      a[i][len(a[i])-1] = 0
      a[i+1][0] += 1
    if a[len(a)-1][len(a[len(a)-1])-1] > 1:
      a[len(a)-1][len(a[len(a)-1])-1] = 0
  print(a)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-08-11
@tumbler

  1. Add more local variables, for example,row=a[i]
  2. Use negative indices for slicesa[-1]
  3. range(len)Use enumerate instead or in generalfor v in a

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question