E
E
exvion2016-07-10 13:07:20
Python
exvion, 2016-07-10 13:07:20

How to make a dictionary from a list of strings in Sublime text 3 in Python?

How to create a dictionary from a simple list of strings? About 1000 lines.
Previously:
Apple Inc.
Google Inc.
Microsoft
Became:
dictionary = { 'Apple Inc.' : '',
'Google Inc.' : '',
'Microsoft' : ''}
How to automate? Plugins, hotkeys?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AtomKrieg, 2016-07-10
@exvion

Ctrl+A
Ctrl+Shift+L
Home
'
End
:'',

S
sim3x, 2016-07-10
@sim3x

dictionary = {}
with open('filename', 'r', encoding="utf-8") as f:
    for l in f:
        dictionary[l.strip()] = ''

D
DDDsa, 2016-07-11
@DDDsa

You can also find \n through search and replace (Ctrl + H) and replace it with ':'',\n'
(do not forget to turn on the reg ex search box, highlighted in the screenshot)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question