Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is my string empty?
#2
In the first place, why are you building a dictionary that maps from position to letter, but then using it to look from letter to position? My first thought is that you should build the dictionary in that direction and use it naturally. What this program does is use the dictionary like a list. It would be simpler to just loop through the original string.ascii_lowercase than loop through the dictionary.

Next, while alphabet_position loops over the characters in the input, it overwrites strin each time through the loop. So only the final character is kept in that variable.

Finally, the function has no return call. So if you are calling it, you will always get back None
Reply


Messages In This Thread
Why is my string empty? - by karabakh - Jan-30-2021, 02:12 AM
RE: Why is my string empty? - by bowlofred - Jan-30-2021, 02:24 AM
RE: Why is my string empty? - by karabakh - Jan-30-2021, 02:29 AM
RE: Why is my string empty? - by deanhystad - Jan-30-2021, 02:54 AM
RE: Why is my string empty? - by bowlofred - Jan-30-2021, 03:52 AM
RE: Why is my string empty? - by karabakh - Jan-30-2021, 04:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  -i option changes sys.path (removes leading empty string '') markanth 6 2,040 Aug-26-2022, 09:27 PM
Last Post: markanth
  build a list (add_animals) using a while loop, stop adding when an empty string is en nikhilkumar 1 8,935 Jul-17-2017, 03:29 PM
Last Post: buran
  if line edit is empty put in a string birdieman 5 4,987 Mar-16-2017, 01:52 PM
Last Post: birdieman

Forum Jump:

User Panel Messages

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