I want to display a dictionary in two columns. I'm basically trying to do what this question was trying to achieve with a list, but I need to do it with a dictionary.
My script prints the directory listing for the current folder, with numbers.
Here is the script:
import os
files = os.listdir(os.curdir) #get directory listing
final_dic = dict() #initialize the dictionary
x = 1
for item in files: #associate index numbers with the filenames
final_dic[x] = item
x+=1
print '''
-------------
| FILE LIST |
-------------
'''
for k, v in final_dic.iteritems(): #print out the enumerated listing
print ('{0}: {1}'.format(k, v))
num = int(raw_input('\nEnter no. of file: ')) #have user select file by no.
print ('\n{0}\n'.format(final_dic[num])) #print out corresp. filename
The output of the file listing is:
-------------
| FILE LIST |
-------------
1: file1
2: file2
3: file3
etc.
The problem is that in folders with a lot of files, the listing scrolls off the top of the screen, so I would like to be able to display the listing like this:
1: file1 4: file4
2: file2 5: file5
3: file3 6: file6
etc.
From the question linked to above, it looks like zip
takes two lists and creates a dictionary out of them, but I've already got a dictionary.
So, is there a way to do this?
Added comment: some of the comments mention that I should use a list, but unfortunately it has to be a dictionary. This is just one part of a larger script.