GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — algorithms/algorithms/tree/pretty_print.py at master · oldmonad/algorithms

Expand file tree

/

pretty_print.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
23 lines (20 loc) · 766 Bytes
/

pretty_print.py

Copy path

File metadata and controls

23 lines (20 loc) · 766 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# a -> Adam -> Book -> 4
# b -> Bill -> Computer -> 5
# -> TV -> 6
# Jill -> Sports -> 1
# c -> Bill -> Sports -> 3
# d -> Adam -> Computer -> 3
# Quin -> Computer -> 3
# e -> Quin -> Book -> 5
# -> TV -> 2
# f -> Adam -> Computer -> 7
from __future__ import print_function
def tree_print(tree):
for key in tree:
print(key, end=' ') # end=' ' prevents a newline character
tree_element = tree[key] # multiple lookups is expensive, even amortized O(1)!
for subElem in tree_element:
print(" -> ", subElem, end=' ')
if type(subElem) != str: # OP wants indenting after digits
print("\n ") # newline and a space to match indenting
print() # forces a newline
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.