1

Let's say I have a 0.txt file:

test1:hello
test2;niceee
test3:;okthen

and a code:

dct = dict()
with open('0.txt', 'r') as md5_file:
    for line in md5_file:
        hash_passw = line.strip().split(":", 1)[1]
        dct[hash_passw] = hash_passw
    print(dct)

Desired output would be:

hello
niceee
okthen

As you can see, every line has different delimiter, and I only know to go around it if all lines had exactly same delimiter : for example as seen in the code. What is the proper way to split the words and only get what is after the delimiter?

uzdisral
  • 414
  • 1
  • 4
  • 16
  • Well your desired output will be difficult to reach as it is not a valid object. Do you mean a dict of dict? Then it misses some curly brackets inside it. – jlandercy Dec 14 '20 at 07:50
  • @jlandercy I've seen the re being used, and somehow I am not able to make it work yet. But to answer your question, it doesn't matter, it could just output as string only – uzdisral Dec 14 '20 at 07:54
  • @Rakesh I don't think this is an appropriate duplicate – Dani Mesejo Dec 14 '20 at 08:04

0 Answers0