0

K = 2 List = '1001101100011' result = re.findall(f'1{k}',List) I'm not getting output ? Can you help

1st May 2021, 7:20 AM
Levi
Levi - avatar
5 Antworten
+ 2
This also works r'1{'+str(k)+'}'
1st May 2021, 8:39 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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)
1st May 2021, 7:39 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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)
1st May 2021, 8:09 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg thanks :)
1st May 2021, 8:44 AM
Levi
Levi - avatar
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 ?
1st May 2021, 7:44 AM
Levi
Levi - avatar