# Write a regex pattern in python to print all adverbs and their positions in user input text - Python

Categories:
Viewed: 2 - Published at: a few seconds ago

### Write a regex pattern in python to print all adverbs and their positions in user input text

``````import re
text = input("Enter a string: ")
for m in re.finditer(r"\w+ly", text):
print('%02d-%02d: %s' % (m.start(), m.end(), m.group(0)))
``````

### Write a python function to return random selection from itertools.permutations(iterable, r)

``````def random_permutation(iterable, r=None):
import random
pool = tuple(iterable)
r = len(pool) if r is None else r
return tuple(random.sample(pool, r))
``````

### Write a python function to random select from itertools.combinations(iterable, r)

``````def random_combination(iterable, r):
import random
pool = tuple(iterable)
n = len(pool)
indices = sorted(random.sample(range(n), r))
return tuple(pool[i] for i in indices)
``````

### Write a python function to perform random selection from itertools.combinationswithreplacement(iterable, r)

``````def random_combination_with_replacement(iterable, r):
import random
pool = tuple(iterable)
n = len(pool)
indices = sorted(random.choices(range(n), k=r))
return tuple(pool[i] for i in indices)
``````

### Write a python function to locate the leftmost value exactly equal to x

``````def index(a, x):
from bisect import bisect_left
i = bisect_left(a, x)
if i != len(a) and a[i] == x:
return i
raise ValueError
``````

### Write a python function to locate the rightmost value less than x

``````def find_lt(a, x):
from bisect import bisect_left
i = bisect_left(a, x)
if i:
return a[i-1]
raise ValueError
``````

### Write a python function to find rightmost value less than or equal to x

``````def find_le(a, x):
from bisect import bisect_right
i = bisect_right(a, x)
if i:
return a[i-1]
raise ValueError
``````

### Write a python function to find leftmost value greater than x

``````def find_gt(a, x):
from bisect import bisect_right
i = bisect_right(a, x)
if i != len(a):
return a[i]
raise ValueError
``````

### Write a python function to find leftmost item greater than or equal to x

``````def find_ge(a, x):
from bisect import bisect_left
i = bisect_left(a, x)
if i != len(a):
return a[i]
raise ValueError
``````

### Write a python function to map a numeric lookup using bisect

``````def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
from bisect import bisect
i = bisect(breakpoints, score)
{"ft_lang_label":"__label__en","ft_lang_prob":0.53617686,"math_prob":0.9886895,"size":2265,"snap":"2023-14-2023-23","text_gpt3_token_len":592,"char_repetition_ratio":0.15081823,"word_repetition_ratio":0.42942944,"special_character_ratio":0.25474614,"punctuation_ratio":0.13318284,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.999608,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-22T01:04:50Z\",\"WARC-Record-ID\":\"<urn:uuid:d448c532-13a1-426d-9e83-e853f5f3cf58>\",\"Content-Length\":\"35032\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9f48865a-a8f4-4e28-a15d-82b7936faed1>\",\"WARC-Concurrent-To\":\"<urn:uuid:f5ff1832-07a6-4789-81dc-0ba82c4db730>\",\"WARC-IP-Address\":\"45.63.49.36\",\"WARC-Target-URI\":\"https://www.codevelop.art/write-a-regex-pattern-in-python-to-print-all-adverbs-and-their-positions-in-user-input-text.html\",\"WARC-Payload-Digest\":\"sha1:FIE6ATDLHFBG6GNWTUB776E7E52YSKLN\",\"WARC-Block-Digest\":\"sha1:MAAISU6WO436JPHTQ57XDIPO2LQ3YUW7\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296943747.51_warc_CC-MAIN-20230321225117-20230322015117-00735.warc.gz\"}"}