Python Forum
phone number, to letters conversion
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
phone number, to letters conversion
#2
Tip: when variable names contain a varying index such as in
tuple0=("","","")
tuple1=("","","")
tuple2=("a","b","c")
tuple3=("d","e","f")
tuple4=("g","h","i")
tuple5=("j","k","l")
tuple6=("m","n","o")
tuple7=("p","q","r","s")
tuple8=("t","u","v")
tuple9=("w","x","y","z")
use a single list variable instead
atuple = [
    ("","",""),
    ("","",""),
    ("a","b","c"),
    ("d","e","f"),
    ("g","h","i"),
    ("j","k","l"),
    ("m","n","o"),
    ("p","q","r","s"),
    ("t","u","v"),
    ("w","x","y","z")]
Then instead of tuple7, use atuple[7]. It allows loops or simplifications such as
list_tuple.append(atuple[int(number)])
Similarly, instead of the variables a, b, c, d, e, f, g, you could use a list to contain them all. Finally, have a look at itertools.product()!
Reply


Messages In This Thread
RE: phone number, to letters conversion - by Gribouillis - Dec-02-2018, 10:22 PM
RE: phone number, to letters conversion - by nilamo - Dec-03-2018, 07:59 PM

Forum Jump:

User Panel Messages

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