Python Forum
Error in dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in dictionaries
#4
You can convert a string to a list using casting, words = list(word), no need to use the list comprehension.

In the while loop, you increment i on both paths through the if statement, so why not have it just once below the if statement? Although, you don't really need a while loop.

Given that you are just looping through words, why not use:

for ch in words: which will give you each letter in turn (you know this already, from using list comprehension earlier).

Why bother with checking if the character is in KEYPAD and then extracting it?
Just use words.get(ch, default_value)

default_value can be left out (in which case, None is returned if there is no match).
I am trying to help you, really, even if it doesn't always seem that way
Reply


Messages In This Thread
Error in dictionaries - by Wolfpack2605 - Jan-03-2018, 11:52 PM
RE: Error in dictionaries - by Larz60+ - Jan-04-2018, 12:03 AM
RE: Error in dictionaries - by ka06059 - Jan-10-2018, 02:11 PM
RE: Error in dictionaries - by gruntfutuk - Jan-11-2018, 04:26 PM

Forum Jump:

User Panel Messages

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