Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a function that looks like this
def mapping(a):
  if a in ["A1" , "A2" , "A3" , "A4" , "A5" , "A6" , "A7"]:
    return "Avyayıbhava"
  elif a in ["Bs2" , "Bs3" , "Bs4" , "Bs5" , "Bs6" , "Bs7" , "Bsd" , "Bss" , "Bsu" , "Bsp" , "Bsg" , "Bvs" , "BvS" , "Bvp" , "BvU" , "Bsmn" , "Bb","BvP"]:
    return "Bahuvrıhi"
  elif a in ['Di' , "Ds" , "E"]:
    return "Dvandva"
  elif a in ["d" , "S"]:
    return "anya"
  elif a in ["T1" , "T2" , "T3" , "T4" , "T5" , "T6" , "T7" , "Tn" , "Tp" , "Tk" , "Tg" , "Td" , "Tdu" , "Tds" , "U" , "U2" , "U3" , "U4" , "U5" , "U7" , "Tm" , "Tb" , "K1" ,"k1" "K2" , "K3" , "K4" , "K5" , "K6" , "K7" , "Km"]:
    return "Tatpurusa"


I tried it and it is working properly. Next up I have a list of tags that looks like this
' Bs6',
 ' T4',
 ' T6',
 ' Tg',
 ' T3',
 ' K1',
 ' T6',
 ' T4',
 ' T3',
 ' T6',
 ' K1',
 ' T6',
 ' T6',
 ' T4',
 ' Bs6',
 ' K1',
 ' Bs6',
 ' T3',
 ' T6',
 ' K1',
 ' T6',
 ' K1',
 ' T6',


It is a much bigger list with tags like this but this serves as a representation. I used the following script to read from the list and return proper values.
coarse_tags=[]
for tag in stringed_tags:
       coarse_tags.append(mapping(tag))


However, this keeps giving me the result of none. Any modifications to the code that could help me? Secondly, the given list has the above w=mentioned values but the tags could be in a different case format too. So Bs1, BS1 and bs1 all exist in the list but refer to the same tag. How do I make the above function case insensitive?

What I have tried:

Created mapping function
def mapping(a):
  if a in ["A1" , "A2" , "A3" , "A4" , "A5" , "A6" , "A7"]:
    return "Avyayıbhava"
  elif a in ["Bs2" , "Bs3" , "Bs4" , "Bs5" , "Bs6" , "Bs7" , "Bsd" , "Bss" , "Bsu" , "Bsp" , "Bsg" , "Bvs" , "BvS" , "Bvp" , "BvU" , "Bsmn" , "Bb","BvP"]:
    return "Bahuvrıhi"
  elif a in ['Di' , "Di" , "E"]:
    return "Dvandva"
  elif a in ["d" , "S"]:
    return "anya"
  elif a in ["T1" , "T2" , "T3" , "T4" , "T5" , "T6" , "T7" , "Tn" , "Tp" , "Tk" , "Tg" , "Td" , "Tdu" , "Tds" , "U" , "U2" , "U3" , "U4" , "U5" , "U7" , "Tm" , "Tb" , "K1" ,"k1" "K2" , "K3" , "K4" , "K5" , "K6" , "K7" , "Km"]:
    return "Tatpurusa"


Wrote script for reading from list and giving correct coarse tag
coarse_tags=[]
for tag in stringed_tags:
       coarse_tags.append(mapping(tag))
Posted
Updated 3-Jun-21 0:25am
v2

1 solution

You have a leading blank in every tag (e.g. ' Bs6').
Try to remove it with lstrip:
Python
coarse_tags=[]
for tag in stringed_tags:
       coarse_tags.append(mapping(tag.lstrip()))
 
Share this answer
 
v2
Comments
adideva98 3-Jun-21 3:54am    
I got the problem but this solution, unfortunately, does not work. The lstrip function does not work inside another function.
CPallini 3-Jun-21 4:05am    
I wrote it wrong, sorry: lstrip is a method.
Please see my updated solution.
Patrice T 3-Jun-21 6:44am    
+5
CPallini 3-Jun-21 6:55am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900