Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is my Tree code too long?
#5
Ok i refactored it to hell, code is super small. See below. But I still wonder am I doing it wrong? - Can the code be smaller? The code functions as desired and is fast and the memory issue is expected.

e=['']
g=4
for count2 in range(2):
  f='ababa'[count2:g]
  g=g+1
  c=1
  d=1
  for count in range(4):
    a=f[count-1]
    b=e[d-1].find(a)+1
    if b==0:
      e[d-1]=str(e[d-1])+str(a)
      if d==len(e):
        e.append([])
      e[d].append(len(e)+1)
      e.append('')
      d=len(e)
    else:
      d=e[d][b-1]
print(e)[b][/b]
Reply


Messages In This Thread
Is my Tree code too long? - by BladedSupernova - Feb-11-2020, 06:45 AM
RE: Is my Tree code too long? - by stullis - Feb-11-2020, 04:09 PM
RE: Is my Tree code too long? - by BladedSupernova - Feb-11-2020, 05:38 PM
RE: Is my Tree code too long? - by BladedSupernova - Feb-11-2020, 08:35 PM
RE: Is my Tree code too long? - by BladedSupernova - Feb-12-2020, 01:26 AM
RE: Is my Tree code too long? - by Larz60+ - Feb-12-2020, 03:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Code for Preorder Traversal of a Binary Tree Bolt 1 688 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  Does this code need to be so long? duckredbeard 4 1,027 Sep-27-2022, 09:36 AM
Last Post: ibreeden
  how long can a line of code be? Skaperen 2 2,291 Jun-09-2021, 06:31 PM
Last Post: Skaperen
  Factorial Code is not working when the given number is very long integer Raj_Kumar 2 2,397 Mar-31-2020, 06:40 PM
Last Post: deanhystad
  Mix-in class tree file not running the self test code. arjunsingh2908 3 3,066 Aug-14-2018, 05:46 PM
Last Post: arjunsingh2908
  What is wrong with code? Bin. Tree counting Peter_EU 3 3,533 Nov-08-2017, 08:41 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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