-
Notifications
You must be signed in to change notification settings - Fork 39
/
questions.json
1657 lines (1657 loc) · 58.8 KB
/
questions.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"0": {
"question": "Match `is` anywhere in the given input strings.",
"fill": "re.search(r'', ip)",
"left column": [
"Regex is awesome",
"Thistle",
"This should also match"
],
"right column": [
"IS",
"grep sed awk ls ip",
"Th1s should not match"
],
"Reference solution": "re.search(r'is', ip)"
},
"1": {
"question": "Match `is` anywhere in the given input strings, irrespective of case.",
"fill": "re.search(r'', ip)",
"left column": [
"Regex is awesome",
"THiStLe",
"THIS SHOULD ALSO MATCH"
],
"right column": [
"first",
"grep sed awk ls ip",
"Th1s should not match"
],
"Reference solution": "re.search(r'(?i)is', ip)\nre.search(r'is', ip, flags=re.I)"
},
"2": {
"question": "Filter all elements that do *not* contain `e`.",
"fill": "[w for w in ip if ]",
"left column": [
"['goal', 'new', 'user', 'sit']",
"['eat', 'dinner']"
],
"right column": [
"['goal', 'sit']",
"[]"
],
"Reference solution": "[w for w in ip if not re.search(r'e', w)]"
},
"3": {
"question": "Replace all occurrences of `5` with `five` for the given strings.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"They ate 5 apples and 5 oranges",
"515515",
"1) 3) 5) 7)"
],
"right column": [
"They ate five apples and five oranges",
"five1fivefive1five",
"1) 3) five) 7)"
],
"Reference solution": "re.sub(r'5', 'five', ip)"
},
"4": {
"question": "Replace only the first occurrence of `5` with `five` for the given strings.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"They ate 5 apples and 5 oranges",
"515515",
"1) 3) 5) 7)"
],
"right column": [
"They ate five apples and 5 oranges",
"five15515",
"1) 3) five) 7)"
],
"Reference solution": "re.sub(r'5', 'five', ip, count=1)"
},
"5": {
"question": "Replace all occurrences of `note` irrespective of case with `X`.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"This note should not be NoTeD"
],
"right column": [
"This X should not be XD"
],
"Reference solution": "re.sub(r'(?i)note', 'X', ip)\nre.sub(r'note', 'X', ip, flags=re.I)"
},
"6": {
"question": "Match lines only if they start with `be`.",
"fill": "re.search(r'', ip)",
"left column": [
"be nice",
"better?",
"best\nview",
"nice\nbell"
],
"right column": [
"\"best!\"",
"abetter",
"oh no\na bear spotted",
"ball\ntell"
],
"Reference solution": "re.search(r'(?m)^be', ip)\nre.search(r'^be', ip, flags=re.M)"
},
"7": {
"question": "Change only whole word `red` to `brown`.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"bred",
"light red.",
"reddish leaf",
"credible",
"red"
],
"right column": [
"bred",
"light brown.",
"reddish leaf",
"credible",
"brown"
],
"Reference solution": "re.sub(r'\\bred\\b', 'brown', ip)"
},
"8": {
"question": "Filter all elements that contain `42` surrounded by word characters.",
"fill": "[w for w in ip if re.search(r'', w)]",
"left column": [
"['hi42bye', 'nice1423', 'bad42']",
"['cool_42a', '42fake', '_42_']"
],
"right column": [
"['hi42bye', 'nice1423']",
"['cool_42a', '_42_']"
],
"Reference solution": "[w for w in ip if re.search(r'\\B42\\B', w)]"
},
"9": {
"question": "Change whole word `mall` to `1234` only if it is at the start of a line.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"(mall) call ball pall\nball fall wall tall\nmall call ball pall\nwall mall ball fall\nmallet wallet malls\nmall:call:ball:pall"
],
"right column": [
"(mall) call ball pall\nball fall wall tall\n1234 call ball pall\nwall mall ball fall\nmallet wallet malls\n1234:call:ball:pall"
],
"Reference solution": "re.sub(r'(?m)^mall\\b', '1234', ip)\nre.sub(r'^mall\\b', '1234', ip, flags=re.M)"
},
"10": {
"question": "Filter all whole elements `12\\nthree` irrespective of case.",
"fill": "[e for e in ip if ]",
"left column": [
"['12\\nthree\\n', '12\\nThree']",
"['412\\nthree']",
"['12\\nthree\\n4', '12\\nthree']"
],
"right column": [
"['12\\nThree']",
"[]",
"['12\\nthree']"
],
"Reference solution": "[e for e in ip if re.fullmatch(r'(?i)12\\nthree', e)]\n[e for e in ip if re.fullmatch(r'12\\nthree', e, flags=re.I)]\n[e for e in ip if re.search(r'(?i)\\A12\\nthree\\Z', e)]"
},
"11": {
"question": "Replace `hand` with `X` for all elements that start with `hand` followed by at least one word character.",
"fill": "[re.sub(r'', '', w) for w in ip]",
"left column": [
"['handed', 'hand']",
"['handy', 'un-handed']",
"['handle', 'hand-2']"
],
"right column": [
"['Xed', 'hand']",
"['Xy', 'un-handed']",
"['Xle', 'hand-2']"
],
"Reference solution": "[re.sub(r'\\Ahand\\B', 'X', w) for w in ip]"
},
"12": {
"question": "Filter all elements starting with `h`. Additionally, replace `e` with `X` for these filtered elements.",
"fill": "[re.sub(r'', '', w) for w in ip if re.search(r'', w)]",
"left column": [
"['handed', 'hand']",
"['handy', 'un-handed']",
"['handle', 'hand-2']"
],
"right column": [
"['handXd', 'hand']",
"['handy']",
"['handlX', 'hand-2']"
],
"Reference solution": "[re.sub(r'e', 'X', w) for w in ip if re.search(r'\\Ah', w)]"
},
"13": {
"question": "Match `to` or `an` anywhere in the given input strings.",
"fill": "re.search(r'', ip)",
"left column": [
"collaborator",
"tool",
"transistor",
"androids"
],
"right column": [
"tea",
"past",
"about",
"Anvil"
],
"Reference solution": "re.search(r'to|an', ip)"
},
"14": {
"question": "Match strings that start with `den` or end with `ly`.",
"fill": "re.search(r'', ip)",
"left column": [
"lovely",
"2 lonely",
"dent"
],
"right column": [
"1\ndentist",
"eden",
"fly\n"
],
"Reference solution": "re.search(r'\\Aden|ly\\Z', ip)"
},
"15": {
"question": "Match lines that start with `den` or end with `ly`.",
"fill": "re.search(r'', ip)",
"left column": [
"lovely",
"2 lonely",
"1\ndentist",
"dent",
"fly\nfar"
],
"right column": [
"eden",
"lying",
"2 den\n3 ten",
"a dentist",
"fly low\nand near"
],
"Reference solution": "re.search(r'(?m)^den|ly$', ip)\nre.search(r'^den|ly$', ip, flags=re.M)"
},
"16": {
"question": "Match `(9-2)*5` anywhere in the given input strings.",
"fill": "re.search(r'', ip)",
"left column": [
"(9-2)*5+qty/3",
"(qty+4)/2-(9-2)*5+pq/4",
"3*(9-2)*55"
],
"right column": [
"9-2)*5",
"3-(9-2)*7",
"(9-2)*15"
],
"Reference solution": "re.search(r'\\(9-2\\)\\*5', ip)"
},
"17": {
"question": "Match `(4)\\|` only at the start or end of given input strings.",
"fill": "re.search(r'', ip)",
"left column": [
"2+(4)\\|",
"good\n5.3-(4)\\|",
"(4)\\|42 - (4)\\|3",
"(4)\\| - 3\nnot bad"
],
"right column": [
"2+(4)\\|a",
"one - (4)\\|\ntwo",
"b(4)\\|42 - (4)\\|3",
"oops\n(4)\\|42"
],
"Reference solution": "re.search(r'\\A\\(4\\)\\\\\\||\\(4\\)\\\\\\|\\Z', ip)"
},
"18": {
"question": "Replace the backspace character `\\b` with a single space character for the given input string.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"123\b456"
],
"right column": [
"123 456"
],
"Reference solution": "re.sub(r'\\x08', ' ', ip)"
},
"19": {
"question": "Replace all occurrences of `\\e` with `e`.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"th\\er\\e ar\\e common asp\\ects",
" among th\\e alt\\ernations"
],
"right column": [
"there are common aspects",
" among the alternations"
],
"Reference solution": "re.sub(r'\\\\e', 'e', ip)"
},
"20": {
"question": "Construct a minimal pattern that satisfies the given sample strings.",
"fill": "re.search(r'', ip)",
"left column": [
"that's so good",
"hit the mark",
"2+gh*t-10"
],
"right column": [
"host",
"he",
"2+gt-h1"
],
"Reference solution": "re.search(r'h.t', ip)"
},
"21": {
"question": "For the given single line strings, remove everything from the first occurrence of `i` till the end of the string.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"remove the special meaning of such",
"characters while constructing",
"input output"
],
"right column": [
"remove the spec",
"characters wh",
""
],
"Reference solution": "re.sub(r'i.*', '', ip)"
},
"22": {
"question": "For the given single line strings, replace everything from the first occurrence of `test` (irrespective of case) till the end of the string with `X`, provided `test` isn't at the end of the string.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"this is a Test",
"always test your RE for corner cases",
"a TEST of skill tests?"
],
"right column": [
"this is a Test",
"always X",
"a X"
],
"Reference solution": "re.sub(r'(?i)test.+', 'X', ip)\nre.sub(r'test.+', 'X', ip, flags=re.I)"
},
"23": {
"question": "Split the given input strings to get the corresponding output as shown below.",
"fill": "re.split(r'', ip)",
"left column": [
"a+42//5-c",
"pressure*3+42/5-14256",
"r*42-5/3+42///5-42/53+a"
],
"right column": [
"['a+', '-c']",
"['pressure*3+', '-14256']",
"['r*42-5/3+42///5-', '3+a']"
],
"Reference solution": "re.split(r'42//?5', ip)"
},
"24": {
"question": "Match `removed` or `reed` or `received` or `refused`.",
"fill": "re.search(r'', ip)",
"left column": [
"creed",
"removed",
"received",
"refused",
"reedy",
"they refused"
],
"right column": [
"redo",
"apple",
"roceived",
"defused",
"resolved",
"reel"
],
"Reference solution": "re.search(r're(mov|ceiv|fus)?ed', ip)"
},
"25": {
"question": "Match whole words `late` or `later` or `slated`.",
"fill": "re.search(r'', ip)",
"left column": [
"don't be late",
"see you later today",
"slated for tomorrow",
"%late.",
"plate (later)",
"slated"
],
"right column": [
"slate",
"liter",
"latent",
"plated",
"slates",
"equilateral"
],
"Reference solution": "re.search(r'\\b(later?|slated)\\b', ip)"
},
"26": {
"question": "Match strings starting with `hand` and followed immediately by at most one more character or `le`.",
"fill": "re.search(r'', ip)",
"left column": [
"hand",
"handy",
"hands",
"handle"
],
"right column": [
"unhand",
"handled",
"handed",
"no hands"
],
"Reference solution": "re.search(r'\\Ahand(.|le)?\\Z', ip)"
},
"27": {
"question": "Match strings containing at least 6 characters.",
"fill": "re.search(r'', ip)",
"left column": [
"sequoia",
"subtle",
"exhibit",
"so this matches",
"12\n345"
],
"right column": [
"tests",
"set",
"site",
"on",
"do\nto"
],
"Reference solution": "re.search(r'(?s).{6}', ip)\nre.search(r'.{6}', ip, flags=re.S)"
},
"28": {
"question": "Filter all elements starting with `se` or `ti` and having a maximum of `7` characters.",
"fill": "[w for w in ip if ]",
"left column": [
"['sequoia', 'subtle']",
"['a set', 'tip']",
"['tin bin', 'set pet let']"
],
"right column": [
"['sequoia']",
"['tip']",
"['tin bin']"
],
"Reference solution": "[w for w in ip if re.fullmatch(r'(se|ti).{,5}', w)]\n[w for w in ip if re.search(r'\\A(se|ti).{,5}\\Z', w)]"
},
"29": {
"question": "Construct a solution using `re.split()` to get the output as shown below for the given input strings.",
"fill": "re.split(r'', ip)",
"left column": [
"go there // \"this // that\"",
"a//b // c//d e//f // 4//5",
"42// hi//bye//see // carefully"
],
"right column": [
"['go there', '\"this // that\"']",
"['a//b', 'c//d e//f // 4//5']",
"['42// hi//bye//see', 'carefully']"
],
"Reference solution": "re.split(r' +// +', ip, maxsplit=1)"
},
"30": {
"question": "For the given strings, extract the matching portion from the first `is` to the last `t`.",
"fill": "",
"left column": [
"thistle",
"missed hit many times"
],
"right column": [
"ist",
"issed hit many t"
],
"Reference solution": "re.search(r'is.*t', ip)[0]\nre.search(r'is.*t', ip).group(0)"
},
"31": {
"question": "Find the starting index of the first occurrence of `is` or `the` or `was` or `to` for the given input strings.",
"fill": "",
"left column": [
"match after the last newline",
"and then you want to test",
"this is good bye then",
"who was there to see?"
],
"right column": [
"12",
"4",
"2",
"4"
],
"Reference solution": "re.search(r'is|the|was|to', ip).start()"
},
"32": {
"question": "Find the starting index of the last occurrence of `is` or `the` or `was` or `to` for the given input strings.",
"fill": "",
"left column": [
"match after the last newline",
"and then you want to test",
"this is good bye then",
"who was there to see?"
],
"right column": [
"12",
"18",
"17",
"14"
],
"Reference solution": "re.search(r'.*(is|the|was|to)', ip).start(1)"
},
"33": {
"question": "The given input strings contain `:` exactly once. Extract all characters after the `:` as output.",
"fill": "",
"left column": [
"fruits:apple, mango, guava",
"blueberry:",
":42"
],
"right column": [
"apple, mango, guava",
"",
"42"
],
"Reference solution": "re.search(r':(.*)', ip)[1]\nre.sub(r'[^:]*:', '', ip)"
},
"34": {
"question": "Replace `cat` with `tiger` and `tiger` with `cat`.",
"fill": "",
"left column": [
"cater tiger cats",
"cat cat tiger cat cat"
],
"right column": [
"tigerer cat tigers",
"tiger tiger cat tiger tiger"
],
"Reference solution": "re.sub(r'cat|tiger', lambda m: {'cat': 'tiger', 'tiger': 'cat'}[m[0]], ip)"
},
"35": {
"question": "Extract all occurrences of `<` up to the next occurrence of `>`, provided there is at least one character in between `<` and `>`.",
"fill": "re.findall(r'', ip)",
"left column": [
"a<ap\nple>\n1<> b<bye> 2<>"
],
"right column": [
"['<ap\\nple>', '<> b<bye>']"
],
"Reference solution": "re.findall(r'(?s)<.+?>', ip)\nre.findall(r'<.+?>', ip, flags=re.S)"
},
"36": {
"question": "Find the sum of comma separated integers. For example, sum of `-2` and `5` is `3`. These groups of integers always end with a space character.",
"fill": "",
"left column": [
"-2,5 4,+3 +42,-53 ",
"4356246,-357532354 "
],
"right column": [
"[3, 7, -11]",
"[-353176108]"
],
"Reference solution": "[int(m[1]) + int(m[2]) for m in re.finditer(r'(.+?),(.+?) ', ip)]"
},
"37": {
"question": "For the given list of strings, change the elements into a tuple of original element and the number of times `t` occurs in that element.",
"fill": "",
"left column": [
"['sequoia', 'attest']",
"['tattletale', 'asset']"
],
"right column": [
"[('sequoia', 0), ('attest', 3)]",
"[('tattletale', 4), ('asset', 1)]"
],
"Reference solution": "[re.subn(r't', 't', w) for w in ip]"
},
"38": {
"question": "The given input string has fields separated by `:`. Each field contains four uppercase alphabets followed optionally by two digits. Ignore the last field, which is empty. Use `'NA'` to represent missing digits.",
"fill": "",
"left column": [
"TWXA42:JWPA:",
"NTED01:"
],
"right column": [
"[('TWXA', '42'), ('JWPA', 'NA')]",
"[('NTED', '01')]"
],
"Reference solution": "[m.groups(default='NA') for m in re.finditer(r'(.{4})(..)?:', ip)]"
},
"39": {
"question": "Convert the comma separated strings to corresponding `dict` objects as shown below. Ignore the empty last field.",
"fill": "",
"left column": [
"maths:75,phy:89,",
"maths:88,phy:92,"
],
"right column": [
"{'maths': '75', 'phy': '89'}",
"{'maths': '88', 'phy': '92'}"
],
"Reference solution": "dict(re.findall(r'(.+?):(.+?),', ip))\n{m[1]:m[2] for m in re.finditer(r'(.+?):(.+?),', ip)}"
},
"40": {
"question": "Match all strings containing `e` or `i` followed by `l` or `n`.",
"fill": "re.search(r'', ip)",
"left column": [
"don't\nsurrender",
"unicorn",
"eel",
"silk",
"this is\ncool"
],
"right column": [
"this is\nbad",
"door",
"empty",
"list",
"never\ngive up"
],
"Reference solution": "re.search(r'(?s)[ei].*[ln]', ip)\nre.search(r'[ei].*[ln]', ip, flags=re.S)"
},
"41": {
"question": "Replace all whole words `reed` or `read` or `red` with `X`.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"redo red credible :read: rod reed"
],
"right column": [
"redo X credible :X: rod X"
],
"Reference solution": "re.sub(r'\\bre[ae]?d\\b', 'X', ip)"
},
"42": {
"question": "Change whole words starting with `hand` and ending immediately with `s` or `y` or `le` to `X.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"handsy hand (handy)\nunhand -hands handle\nhanda hand2 handled"
],
"right column": [
"handsy hand (X)\nunhand -X X\nhanda hand2 handled"
],
"Reference solution": "re.sub(r'\\bhand([sy]|le)\\b', 'X', ip)"
},
"43": {
"question": "Extract all hex character sequences, with `0x` optional prefix. Match the characters case insensitively, and the sequences shouldn't be surrounded by other word characters.",
"fill": "",
"left column": [
"128A foo 0xfe32 34 0xbar",
"0XDEADBEEF place 0x0ff1ce bad"
],
"right column": [
"['128A', '0xfe32', '34']",
"['0XDEADBEEF', '0x0ff1ce', 'bad']"
],
"Reference solution": "re.findall(r'(?i)\\b(?:0x)?[\\da-f]+\\b', ip)\nre.findall(r'\\b(?:0x)?[\\da-f]+\\b', ip, flags=re.I)"
},
"44": {
"question": "Delete from `(` to the next occurrence of `)` unless they contain parentheses characters in between.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"def factorial()",
"c%d(#modulo) - (e+(j/k-3)*4(x))",
"Hi there(bye). Nice day(a(b)"
],
"right column": [
"def factorial",
"c%d - (e+*4)",
"Hi there. Nice day(a"
],
"Reference solution": "re.sub(r'\\([^()]*\\)', '', ip)"
},
"45": {
"question": "Match strings not starting with `e` or `p` or `u`.",
"fill": "re.search(r'', ip)",
"left column": [
"surrender unicorn newer _b",
"door empty 2good eel",
"(end)",
"Pest"
],
"right column": [
"early",
"present",
"unit: m",
"eel"
],
"Reference solution": "re.search(r'\\A[^epu]', ip)"
},
"46": {
"question": "Match strings containing `u` or `w` or `ee` or `-`.",
"fill": "re.search(r'', ip)",
"left column": [
"p-t",
"thank you",
"heel",
"owe",
"-"
],
"right column": [
"tea",
"ear",
"cat",
"bad",
"hello there"
],
"Reference solution": "re.search(r'[uw-]|ee', ip)"
},
"47": {
"question": "The given input strings contain fields separated by `,` and fields can be empty too. Replace the last three fields with `WHTSZ323`.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"(2),kite,12,,D,C,,",
"hi,bye,sun,moon"
],
"right column": [
"(2),kite,12,,D,WHTSZ323",
"hi,WHTSZ323"
],
"Reference solution": "re.sub(r'(,[^,]*){3}\\Z', ',WHTSZ323', ip)"
},
"48": {
"question": "Extract whole words starting with `r` or `s` or `t` and having a maximum of `6` word characters.",
"fill": "re.findall(r'', ip)",
"left column": [
"sequoia subtle-exhibit tHR33",
"asset%sets preset tests",
"site present re_do Tea"
],
"right column": [
"['subtle', 'tHR33']",
"['sets', 'tests']",
"['site', 're_do']"
],
"Reference solution": "re.findall(r'\\b[rst]\\w{,5}\\b', ip)"
},
"49": {
"question": "Split the given strings based on consecutive sequence of digit or whitespace characters.",
"fill": "re.split(r'', ip)",
"left column": [
"lion \t Ink32onion Nice",
"**1\t2\n3star 7 77\t**\nform\ffeed"
],
"right column": [
"['lion', 'Ink', 'onion', 'Nice']",
"['**', 'star', '**', 'form', 'feed']"
],
"Reference solution": "re.split(r'[\\d\\s]+', ip)"
},
"50": {
"question": "Construct a pattern that splits the given input string to get the output as shown below.",
"fill": "re.split(r'', ip)",
"left column": [
"food:good",
"food:good-cool",
"one:two-three;four",
"42:no-op;10:car-tr:u-ck;SQ49"
],
"right column": [
"['food:good']",
"['food:good-cool']",
"['one', 'three', 'four']",
"['42', 'op', '10', 'tr:u-ck', 'SQ49']"
],
"Reference solution": "re.split(r':[^-]+-([^;]+);', ip)"
},
"51": {
"question": "Delete all occurrences of the sequence `<characters>` where `characters` is one or more non `>` characters and cannot be empty.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"a<ap\nple>\n1<> b<bye> 2<>\nc<cat>"
],
"right column": [
"a\n1<> b 2<>\nc"
],
"Reference solution": "re.sub(r'<[^>]+>', '', ip)"
},
"52": {
"question": "Filter all elements containing any number sequence greater than `624`.",
"fill": "",
"left column": [
"['hi0000432abcd', 'car00625']",
"['42_624 0512']",
"['624', '3.14 96 2 hi1234bye']"
],
"right column": [
"['car00625']",
"[]",
"['3.14 96 2 hi1234bye']"
],
"Reference solution": "[e for e in ip if any(int(m[0])>624 for m in re.finditer(r'\\d+', e))]"
},
"53": {
"question": "By default, the `str.split()` method will split on whitespace and remove empty strings from the result. Which `re` module function would you use to replicate this functionality?",
"fill": "",
"left column": [
" so pole\t\t\t\n\nlit in \n\n\n to"
],
"right column": [
"['so', 'pole', 'lit', 'in', 'to']"
],
"Reference solution": "re.findall(r'\\S+', ip)"
},
"54": {
"question": "Convert the given input string to the output list as shown below.",
"fill": "",
"left column": [
"p_42 hi^\t\n^-ice==cat\nto"
],
"right column": [
"['p_42', 'hi', 'ice', 'cat', 'to']"
],
"Reference solution": "re.split(r'\\W+', ip)\nre.findall(r'\\w+', ip)"
},
"55": {
"question": "Match strings whose first non-whitespace character is not a `#` character. Any string made up of only whitespace characters should not be matched.",
"fill": "re.search(r'', ip)",
"left column": [
"sure",
"\t\napple #42",
"no#1"
],
"right column": [
"#oops",
"\t\n",
" #comment"
],
"Reference solution": "re.search(r'\\A\\s*[^#\\s]', ip)\nre.search(r'\\A\\s*+[^#]', ip) # Python3.11+"
},
"56": {
"question": "Match integer numbers greater than or equal to `100` where these numbers can optionally have leading zeros.",
"fill": "re.findall(r'', ip)",
"left column": [
"314 12",
"apple,00984",
"1234:42::001",
"0501 035 154 12 26 98234"
],
"right column": [
"['314']",
"['00984']",
"['1234']",
"['0501', '154', '98234']"
],
"Reference solution": "re.findall(r'0*[1-9]\\d{2,}', ip)\nre.findall(r'0*+\\d{3,}', ip) # Python3.11+"
},
"57": {
"question": "Filter all whole elements with optional whitespaces at the start followed by three to five non-digit characters. Whitespaces at the start should not be part of the calculation for non-digit characters.",
"fill": "",
"left column": [
"['\\t \\ncat', 'goal']",
"[' oh', 'he-he', 'goal2']",
"['ok ', 'sparrow']"
],
"right column": [
"['\\t \\ncat', 'goal']",
"['he-he']",
"['ok ']"
],
"Reference solution": "[e for e in ip if re.fullmatch(r'\\s*[^\\d\\s]\\D{2,4}', e)]\n[e for e in ip if re.fullmatch(r'\\s*+\\D{3,5}', e)] # Python3.11+"
},
"58": {
"question": "Replace the space character that occurs after a word ending with `a` or `r` with a newline character.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"area not a _a2_ roar took 22 a;"
],
"right column": [
"area\nnot a\n_a2_ roar\ntook 22 a;"
],
"Reference solution": "re.sub(r'([ar]) ', r'\\1\\n', ip)"
},
"59": {
"question": "Swap words that are separated by a comma.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"good,bad (42,24)",
"report_log,power_report"
],
"right column": [
"bad,good (24,42)",
"power_report,report_log"
],
"Reference solution": "re.sub(r'(\\w+),(\\w+)', r'\\2,\\1', ip)"
},
"60": {
"question": "Add `[]` around words starting with `s` and containing `e` and `t` in any order.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"sequoia sUBtLe exhibit",
"asset sets2 tests si_te"
],
"right column": [
"sequoia [sUBtLe] exhibit",
"asset [sets2] tests [si_te]"
],
"Reference solution": "re.sub(r'\\bs\\w*(e\\w*t|t\\w*e)\\w*', r'[\\g<0>]', ip)"
},
"61": {
"question": "Change `[digits]` to `(digits0)`. For example, `[10]` should be changed to `(100)`.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"hi [apple] [5] [ball] [0]",
"[20] pens",
"(3) pencils [3.14]"
],
"right column": [
"hi [apple] (50) [ball] (00)",
"(200) pens",
"(3) pencils [3.14]"
],
"Reference solution": "re.sub(r'\\[(\\d+)]', r'(\\g<1>0)', ip)\nre.sub(r'\\[(\\d+)]', r'(\\1\\060)', ip)"
},
"62": {
"question": "Replace all whole words with `X` that start and end with the same word character (irrespective of case). Single character word should get replaced with `X` too, as it satisfies the stated condition.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"oreo not a _a2_ Roar took 22"
],
"right column": [
"X not X X X took X"
],
"Reference solution": "re.sub(r'(?i)\\b(\\w)(\\w*\\1)?\\b', 'X', ip)\nre.sub(r'(?i)\\b(\\w|(\\w)\\w*\\2)\\b', 'X', ip)"
},
"63": {
"question": "Convert the given markdown anchors to hyperlinks as shown below.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"# <a name=\"regex\"></a>Regex",
"## <a name=\"tip-1\"></a>Tip 1"
],
"right column": [
"[Regex](#regex)",
"[Tip 1](#tip-1)"
],
"Reference solution": "re.sub(r'[^\"]+\"([^\"]+)\"></a>(.+)', r'[\\2](#\\1)', ip)"
},
"64": {
"question": "Duplicate the first field and add it as the last field. Consider comma as the field separator and fields other than the first field could be empty too.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"fork,42,nice,3.14",
"good,food",
"2",
"(a^b),#hi#,,"
],
"right column": [
"fork,42,nice,3.14,fork",
"good,food,good",
"2,2",
"(a^b),#hi#,,,(a^b)"
],
"Reference solution": "re.sub(r'\\A([^,]+),?.*', r'\\g<0>,\\1', ip)"
},
"65": {
"question": "Match strings with words that have at least two occurrences of consecutive repeated word characters. For example, words like `stillness` and `Committee` should be matched but not words like `root` or `readable` or `rotational`.",
"fill": "re.search(r'', ip)",
"left column": [
"oppressed abandon accommodation",
"committed apparition innkeeper",
"occasionally afforded",
"depended successfully succeeded"
],
"right column": [
"abandoned building",
"horror apparition",
"afforded luxury",
"cleanliness"
],
"Reference solution": "re.search(r'(\\w*(\\w)\\2){2}', ip)\nre.search(r'(\\w)\\1\\w*(\\w)\\2', ip)"
},
"66": {
"question": "Replace all consecutive occurrences of duplicate words with a single copy. Consider the words to be separated by a single space character only.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"aa a a a 42 f_1 f_1 f_13.14 a"
],
"right column": [
"aa a 42 f_1 f_13.14 a"
],
"Reference solution": "re.sub(r'\\b(\\w+)( \\1)+\\b', r'\\1', ip)"
},
"67": {
"question": "For the given input strings, replace all occurrences of digit sequences with only the unique non-repeating sequence. For example, `232323` should be changed to `23` and `897897` should be changed to `897`. If there no repeats (for example `1234`) or if the repeats end prematurely (for example `12121`), it should not be changed.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"1234 2323 453545354535",
"9339 11 60260260"
],
"right column": [
"1234 23 4535",
"9339 1 60260260"
],
"Reference solution": "re.sub(r'\\b(\\d+)\\1+\\b', r'\\1', ip)"
},
"68": {
"question": "Replace sequences made up of words separated by `:` or `.` by the first word of the sequence. Such sequences will end when `:` or `.` is not followed by a word character.",
"fill": "re.sub(r'', '', ip)",
"left column": [
"wow:Good:2_two.five: hi-2",