Python Forum
Where did this dictionary come from?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where did this dictionary come from?
#1
Please help me understand where this output comes from when I input just the enter key:

{33: None, 34: None, 35: None, 36: None, 37: None, 38: None, 39: None, 40: None, 41: None, 42: None, 43: None, 44: None, 45: None, 46: None, 47: None, 58: None, 59: None, 60: None, 61: None, 62: None, 63: None, 64: None, 91: None, 92: None, 93: None, 94: None, 95: None, 96: None, 123: None, 124: None, 125: None, 126: None}
<class 'dict'>

Here's my code:
import string

contacts = {}
#line = []
count = 0 #continue/stop counter

while count == 0:
    print("To create contacts dictionary, enter <last name>, <first name>, <phone number>.  ")
    rawcntc = input("If done type DONE: ")
    if rawcntc == "DONE":
        count = 1
        continue #this "if" block works fine...
    else: #...this "else" block does not.
        translation = rawcntc.maketrans("","",string.punctuation) #still a string... or evidently not??
        print(translation) #debug
        print(type(translation)) #debug
I'm really not understanding the syntax of the translate method. I've gotten "ValueError: the first two maketrans arguments must have equal length" multiple times in trying to figure this out [maybe when typing (",",string.punctuation) rather than ("","",string.punctuation) ].

Thank you!

I did notice there are the same number of characters (32) in string.punctuation as there are entries in the dictionary: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ . Do those numbers somehow correspond to those characters?
Reply


Messages In This Thread
Where did this dictionary come from? - by Mark17 - Sep-23-2019, 03:47 PM
RE: Where did this dictionary come from? - by buran - Sep-23-2019, 04:13 PM
RE: Where did this dictionary come from? - by buran - Sep-23-2019, 06:31 PM

Forum Jump:

User Panel Messages

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