Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is my string empty?
#1
Hi,

I want to create a loop that would attach the ids from a certain dictionary to a string, space between ids.

import string

letters = list(string.ascii_lowercase)

dic = {}
lista = []
strin=()
final=[]
for id, i in enumerate(letters):
    dic[id]=i

def alphabet_position(text):
    for i in text:
           strin=' '.join([str(k+1)+v for k,v in dic.items() if v == i.lower()])
But the 'strin' returned is empty. It works fine when I remove the condition in the list comprehension (if v==i.lower())).

Why? Thank you
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,032 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,929 Jul-17-2017, 03:29 PM
Last Post: buran
  if line edit is empty put in a string birdieman 5 4,980 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