Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint out dictionary in a table format?
    text
    copied!<p>I have a dictionary that looks like:</p> <pre><code>band2 = {'channel11': [10812, 2162, 1972, 0], 'channel10': [10787, 2157, 1967, 0], 'channel3': [10612, 2122, 1932, 0], 'channel2': [10589, 2117, 1927, 0], 'channel1': [10564, 2112, 1922, 20], 'channel7': [10712, 2142, 1952, 26], 'channel6': [10687, 2137, 1947, 0], 'channel5': [10662, 2132, 1942, 32], 'channel4': [10637, 2127, 1937, 26], 'channel9': [10762, 2152, 1962, 0], 'channel8': [10737, 2147, 1957, 0], 'channel12': [10837, 2167, 1977, 15]} </code></pre> <p>I then sort it like so:</p> <pre><code>zipped = zip(*((key, value) for key, value in sorted(band2.items(), key= lambda x: int(x[0][7:])))) </code></pre> <p>This gives this result:</p> <pre><code>[('channel1', 'channel2', 'channel3', 'channel4', 'channel5', 'channel6', 'channel7', 'channel8', 'channel9', 'channel10', 'channel11', 'channel12'), ([10564, 2112, 1922, 20], [10589, 2117, 1927, 0], [10612, 2122, 1932, 0], [10637, 2127, 1937, 26], [10662, 2132, 1942, 32], [10687, 2137, 1947, 0], [10712, 2142, 1952, 26], [10737, 2147, 1957, 0], [10762, 2152, 1962, 0], [10787, 2157, 1967, 0], [10812, 2162, 1972, 0], [10837, 2167, 1977, 15])] </code></pre> <p>I am wondering how do i print this out in a certain format:</p> <pre><code>Channel 1 Channel 2 ...... Channel 12 value[0] value[0] ........value[0] value[1]/value[2] value[1]/value[2].....value[1]/value[2] value[3] value[3]...........value[3] </code></pre> <p>So an example output would be:</p> <pre><code>Channel 1 Channel 2 &lt;other values&gt; Channel 12 10564 10589 &lt;other values&gt; 10837 2112/1922 2117/1927 &lt;other values&gt; 2167/1977 20 0 &lt;other values&gt; 15 </code></pre> <p>I'm unsure how to go about printing this in a neat table, would I use format?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload