Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My dict is not good
#1
I want to create a dict from txt file, with words & summed ascii value but once again I have been defeated.
I guess I have never really understood dicts, in Python they arent intuitive at all and I just keep forgetting it all.

My worthless struggles:
#   coding=utf-8

coded, words = open("scrambled-words.txt", "r", encoding="UTF-8"), open("dictionary.txt", encoding="UTF-8")
coded, words = [x.strip('\n') for x in coded], [x.strip('\n') for x in words]

def bit_ops(coded, words):
    bit_list = {}
    for x in coded:
        bit_list = dict(zip(coded, [ord(y) for y in x]))
    print(bit_list)
Gets me pathethic results like :

Output:
{'dnaoyt': 116, 'cinuertdso': 115, 'bda': 115, 'haey': 101, 'tolpap': 101, 'slaayr': 110, 'eortem': 118}
I have tried few other things with '__setitem__' and 'update' and I failed too, so Im out of ideas.
Reply


Messages In This Thread
My dict is not good - by blackknite - Sep-22-2019, 02:03 PM
RE: My dict is not good - by ichabod801 - Sep-22-2019, 02:49 PM
RE: My dict is not good - by ndc85430 - Sep-22-2019, 02:50 PM
RE: My dict is not good - by blackknite - Sep-22-2019, 03:22 PM
RE: My dict is not good - by perfringo - Sep-23-2019, 03:22 AM
RE: My dict is not good - by wavic - Sep-23-2019, 08:21 AM
RE: My dict is not good - by blackknite - Sep-23-2019, 09:29 AM
RE: My dict is not good - by wavic - Sep-23-2019, 10:01 AM
RE: My dict is not good - by blackknite - Sep-23-2019, 10:44 AM
RE: My dict is not good - by buran - Sep-23-2019, 10:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a dict in dict cherry_cherry 4 80,876 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020