0
K = 2 List = '1001101100011' result = re.findall(f'1{k}',List) I'm not getting output ? Can you help
5 Antworten
+ 2
This also works
r'1{'+str(k)+'}'
+ 1
1. I don't see the import for re
2. You have K = 2 and then refer to it as k in your pattern string (probably just a typo)
3. You don't have any print() statements for output.
4. Change your f-string to a raw string. f should be r ... or rather fr/rf
import re
k = 2
lst = '1001101100011'
result = re.findall(r'1{%s}' % k, lst)
print(result)
+ 1
Levi
Sorry, it should be;
rf"1{{k}}"
but for whatever reason it's not working here.
This however does work
result = re.findall(r"1{%s}" % k, lst)
+ 1
ChaoticDawg thanks :)
0
ChaoticDawg
Forget about the first 3 things that you told and I already included what u said in my actual program.
If I give raw string then how will the value of k will be replaced by 2 ? What if I assign some other value to k ?