python - How to retrieve a specific field whith a special character in a list -


i have list contains fields:

msg = ['you', 'must', 'pay', 'before', '$id2{8},', 'your', 'balance', 'is', '$id1{5}'] 

i want retrieve fields contain character $ , put them in variable

i've tried this, don't know how can specify fields contain $:

for iter in msg:      if iter == "...":         print iter  

for item in msg:          if '$' in item:         starting=item.index('{')         ending=item.index('}')          print item[3:starting],item[starting+1:ending]  

you can search if '$' in item

u can try

lis=[(item[3],item[5]) item in msg if item .startwith('$') ] 

note: please not use iter variable built in function in python


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -