fork download
  1.  
  2. menu = {"/": []}
  3.  
  4. def add(name, where, category = ""):
  5. if ( where == "/" and category != "" ):
  6. if ( not category in menu["/"] ):
  7. menu["/"].append(category)
  8. where = category
  9. if ( not where in menu ):
  10. menu[where] = []
  11. menu[where].append(name)
  12.  
  13. def printMenu(root, prefix = ""):
  14. if ( len(menu[root]) == 1 and menu[root][0] in menu ):
  15. printMenu(menu[root][0], prefix)
  16. else:
  17. for item in sorted(menu[root]):
  18. print prefix, item
  19. if ( item in menu ):
  20. printMenu(item, prefix + " ")
  21.  
  22. default = "/"
  23. add("WebPositive", default, "Internet") #added at default location
  24. add("Mail", "Internet", "Messages") #added at user-defined location
  25. add("MediaPlayer", default, "Multimedia")
  26. add("Utilities", "/") #subfolder
  27. add("Files", "Utilities") #subfolder of Utilities
  28. add("Expander", "Files") #add to Files
  29.  
  30. print menu
  31. printMenu("/")
  32.  
Success #stdin #stdout 0.08s 8888KB
stdin
Standard input is empty
stdout
{'Files': ['Expander'], 'Multimedia': ['MediaPlayer'], 'Utilities': ['Files'], '/': ['Internet', 'Multimedia', 'Utilities'], 'Internet': ['WebPositive', 'Mail']}
 Internet
   Mail
   WebPositive
 Multimedia
   MediaPlayer
 Utilities
   Expander