I am new to this community, I have tried this below code, this works fine, but looking for a better way of approaching for performance.
Please edit my question, it it is not understandable.
I have a string and list, I need to filter that and converting that string to a dictionary , then if a dictionary key presents in the list, we need to append the corresponding dict[value] to my list
text='p.O(post office)\nR.J(Radio Jocky)'
list1=["R.J"]
text_splitted=text.split("\n")
my_dict={}
for item in text_splitted:
index=item.index("(")
key=item[:index]
value=item[index+1:len(item)-1]
my_dict[key]=value
list2=[my_dict[item] for item in my_dict.keys() if item in list1]
list1=list1+list2
output:
list1=['R.J', 'Radio Jocky']
name(job)\n...
? \$\endgroup\$R.J is already present in list1' so im adding the meaning of
R.J` in the same list. To get this result im converting to dictionary and extracting the values. If there is any easy solution, please answer it \$\endgroup\$name(job,time)
\$\endgroup\$