Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is my Tree code too long?
#4
Also I made the code smaller, is it really small now for what it does or not at all?? Just curious.

tree = ['']
window_start = 1
window_end = 4
for count2 in range(2):
  window = 'ababa'[window_start - 1 : window_end]
  window_start = window_start + 1
  window_end = window_end + 1
  char_location = 1
  node = 1
  for count in range(4):
    char_in_window = window[char_location - 1]
    char_location = char_location + 1
    char_index = tree[node - 1].find(char_in_window) + 1
    if char_index == 0:
      tree[node - 1] = str(tree[node - 1]) + str(char_in_window)
      if node == len(tree):
        tree.append([])
      tree[(node + 1 - 1)].append(len(tree) + 1)
      tree.append('')
      node = len(tree)
    else:
      node = tree[(node + 1 - 1)][char_index - 1]
print(tree)
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 2,076 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  Does this code need to be so long? duckredbeard 4 1,961 Sep-27-2022, 09:36 AM
Last Post: ibreeden
  how long can a line of code be? Skaperen 2 3,073 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 3,269 Mar-31-2020, 06:40 PM
Last Post: deanhystad
  Mix-in class tree file not running the self test code. arjunsingh2908 3 3,864 Aug-14-2018, 05:46 PM
Last Post: arjunsingh2908
  What is wrong with code? Bin. Tree counting Peter_EU 3 4,279 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