-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.json
More file actions
4612 lines (4612 loc) · 170 KB
/
dataset.json
File metadata and controls
4612 lines (4612 loc) · 170 KB
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
[
{
"id": 1,
"input": "def fibonacci(n):\n a, b = 0, 1\n for _ in range(n):\n yield a\n a, b = b, a + b",
"output": "Generates the first 'n' numbers of the Fibonacci sequence."
},
{
"id": 2,
"input": "data = [1, 5, 2, 8]\nsorted_data = sorted(data)",
"output": "Sorts a list of numbers into a new list (ascending order)."
},
{
"id": 3,
"input": "my_dict = {'a': 1, 'b': 2}\nvalue = my_dict.get('d', 'Not Found')",
"output": "Safely gets value for key 'd', using 'Not Found' as default."
},
{
"id": 4,
"input": "squared_numbers = [x**2 for x in range(10) if x % 2 == 0]",
"output": "List comprehension for squared even numbers from 0 to 9."
},
{
"id": 5,
"input": "def is_palindrome(s):\n return s == s[::-1]",
"output": "Checks if string 's' is a palindrome using slicing."
},
{
"id": 6,
"input": "try:\n result = 10 / 0\nexcept ZeroDivisionError:\n result = 'Cannot divide by zero'",
"output": "Handles 'ZeroDivisionError' when dividing by zero."
},
{
"id": 7,
"input": "with open('data.txt', 'r') as file:\n content = file.read()",
"output": "Opens and reads entire content of 'data.txt', closes file automatically."
},
{
"id": 8,
"input": "def greet(name, message='Hello'):\n return f'{message}, {name}!'",
"output": "Returns a greeting with an optional default message."
},
{
"id": 9,
"input": "from collections import Counter\nwords = ['a', 'b', 'a']\nword_counts = Counter(words)",
"output": "Counts frequency of all items in the 'words' list."
},
{
"id": 10,
"input": "data_tuple = (1, 2, 3)\na, b, c = data_tuple",
"output": "Unpacks elements of a tuple into three variables."
},
{
"id": 11,
"input": "def recursive_sum(n):\n if n <= 1:\n return n\n return n + recursive_sum(n - 1)",
"output": "Calculates the sum of integers up to 'n' recursively."
},
{
"id": 12,
"input": "def calculate_average(*args):\n return sum(args) / len(args)",
"output": "Calculates the average of a variable number of arguments."
},
{
"id": 13,
"input": "matrix = [[1], [3, 4]]\nflat_list = [item for row in matrix for item in row]",
"output": "Flattens a two-dimensional list (matrix) into a single list."
},
{
"id": 14,
"input": "class Dog:\n def __init__(self, name):\n self.name = name",
"output": "A basic class 'Dog' with a method to set the name."
},
{
"id": 15,
"input": "my_list = [10, 20]\nmy_list.append(30)\nmy_list.pop(0)",
"output": "Appends 30 to the list, then removes the first element."
},
{
"id": 16,
"input": "import math\narea = math.pi * (5 ** 2)",
"output": "Uses 'math.pi' to calculate the area of a circle with radius 5."
},
{
"id": 17,
"input": "names = ['A', 'B']\nfor index, name in enumerate(names):\n print(index, name)",
"output": "Iterates over a list, getting both the index and the value."
},
{
"id": 18,
"input": "numbers = {1, 2, 3, 3}\nunique_count = len(numbers)",
"output": "Creates a set to count the number of unique elements."
},
{
"id": 19,
"input": "def check_age(age):\n assert age >= 0, 'Age cannot be negative'",
"output": "Uses 'assert' to ensure the 'age' parameter is non-negative."
},
{
"id": 20,
"input": "user_input = input('Enter name: ')\nif user_input:\n print(user_input)",
"output": "Prompts for input and prints it only if not empty."
},
{
"id": 21,
"input": "message = 'Hello world'\nchar_count = len(message)",
"output": "Calculates the number of characters in the string 'message'."
},
{
"id": 22,
"input": "text = 'example'\nreversed_text = ''.join(reversed(text))",
"output": "Reverses a string using the 'reversed' function and 'join'."
},
{
"id": 23,
"input": "nums = [1, 2, 3]\nnums.insert(1, 99)",
"output": "Inserts the value 99 into the list 'nums' at index 1."
},
{
"id": 24,
"input": "def print_info(**kwargs):\n for key, value in kwargs.items():\n print(f'{key}: {value}')",
"output": "Prints key-value pairs from keyword arguments."
},
{
"id": 25,
"input": "colors = ['red', 'blue', 'green']\nfor color in colors:\n if color == 'blue':\n break",
"output": "Iterates until 'blue' is found, then stops the loop."
},
{
"id": 26,
"input": "if temperature > 30:\n status = 'Hot'\nelif temperature < 10:\n status = 'Cold'\nelse:\n status = 'Mild'",
"output": "Assigns a status based on the value of 'temperature'."
},
{
"id": 27,
"input": "names = ['A', 'B', 'C']\njoined_names = ', '.join(names)",
"output": "Concatenates list elements into a single string separated by ', '."
},
{
"id": 28,
"input": "def power(base, exp):\n return base ** exp",
"output": "Calculates the exponent of a base number."
},
{
"id": 29,
"input": "from datetime import datetime\nnow = datetime.now()",
"output": "Gets the current date and time using the 'datetime' module."
},
{
"id": 30,
"input": "numbers = [5, 1, 4]\nnumbers.sort()",
"output": "Sorts the 'numbers' list in-place (modifies the original list)."
},
{
"id": 31,
"input": "data = [1, None, 3, None, 5]\nfiltered = [x for x in data if x is not None]",
"output": "Removes all 'None' values from the list using list comprehension."
},
{
"id": 32,
"input": "user = {'name': 'Alice', 'age': 30}\nif 'name' in user:\n print(user['name'])",
"output": "Checks if the 'name' key exists in the dictionary and prints its value."
},
{
"id": 33,
"input": "def process_data(data):\n pass",
"output": "A function that is defined but currently does nothing (placeholder)."
},
{
"id": 34,
"input": "count = 0\nwhile count < 5:\n print(count)\n count += 1",
"output": "A while loop that iterates and prints 'count' from 0 to 4."
},
{
"id": 35,
"input": "def safe_divide(a, b):\n return a / b if b != 0 else 0",
"output": "Divides 'a' by 'b', returning 0 if 'b' is zero (ternary operator)."
},
{
"id": 36,
"input": "points = [(1, 2), (3, 4)]\nfor x, y in points:\n print(x, y)",
"output": "Iterates over a list of tuples, unpacking each tuple into 'x' and 'y'."
},
{
"id": 37,
"input": "import random\nrand_num = random.randint(1, 10)",
"output": "Generates a random integer between 1 and 10 (inclusive)."
},
{
"id": 38,
"input": "text = 'python is great'\ncapitalized = text.title()",
"output": "Capitalizes the first letter of every word in the string."
},
{
"id": 39,
"input": "my_set = {1, 2, 3}\nmy_set.add(4)",
"output": "Adds the element 4 to the set 'my_set'."
},
{
"id": 40,
"input": "def double(x):\n return x * 2\nresult = double(10)",
"output": "A simple function that multiplies its input by 2."
},
{
"id": 41,
"input": "def logger(func):\n def wrapper(*args, **kwargs):\n print('Calling function...')\n return func(*args, **kwargs)\n return wrapper",
"output": "A basic Python decorator function for logging function calls."
},
{
"id": 42,
"input": "class Animal:\n def speak(self):\n raise NotImplementedError",
"output": "A base class method that forces subclasses to implement their own 'speak' method."
},
{
"id": 43,
"input": "def get_defaults(a, b=1, c=2):\n return a + b + c",
"output": "Function with required argument 'a' and two optional arguments 'b' and 'c'."
},
{
"id": 44,
"input": "import os\nfile_list = os.listdir('.')",
"output": "Gets a list of all files and directories in the current directory."
},
{
"id": 45,
"input": "data = {'a': 1, 'b': 2}\nfor key in data.keys():\n print(key)",
"output": "Iterates over and prints only the keys of the dictionary."
},
{
"id": 46,
"input": "my_string = ' strip me '\ntrimmed = my_string.strip()",
"output": "Removes leading and trailing whitespace from the string."
},
{
"id": 47,
"input": "def greet_all(names):\n for name in names:\n yield f'Hi {name}'",
"output": "A generator that yields a greeting for each name in the list."
},
{
"id": 48,
"input": "num = 5\nif num % 2 == 0:\n print('Even')\nelse:\n print('Odd')",
"output": "Checks if the number is even or odd using the modulo operator."
},
{
"id": 49,
"input": "numbers = [1, 2, 3, 4]\nresult = list(map(lambda x: x * 2, numbers))",
"output": "Uses 'map' with a 'lambda' function to double every number in the list."
},
{
"id": 50,
"input": "def print_message():\n global count\n count = 10\n print(count)",
"output": "Modifies a global variable 'count' inside the function."
},
{
"id": 51,
"input": "import sys\nprint(sys.version)",
"output": "Prints the current Python interpreter version."
},
{
"id": 52,
"input": "user_data = ('John', 25)\nname, age = user_data",
"output": "Assigns elements of a two-item tuple to separate variables."
},
{
"id": 53,
"input": "s1 = {1, 2, 3}\ns2 = {3, 4, 5}\nunion = s1.union(s2)",
"output": "Calculates the union (all unique elements) of two sets."
},
{
"id": 54,
"input": "text = 'hello'\nif text.startswith('h'):\n print('Starts with h')",
"output": "Checks if the string 'text' begins with the letter 'h'."
},
{
"id": 55,
"input": "def sum_and_prod(a, b):\n return a + b, a * b",
"output": "Returns both the sum and the product of two numbers as a tuple."
},
{
"id": 56,
"input": "class Car:\n color = 'Red'",
"output": "A class 'Car' with a single class-level attribute 'color'."
},
{
"id": 57,
"input": "numbers = [1, 2, 3]\ncount = numbers.count(2)",
"output": "Counts how many times the number 2 appears in the list."
},
{
"id": 58,
"input": "for i in range(10):\n if i == 5:\n continue\n print(i)",
"output": "Prints numbers from 0 to 9, skipping the number 5."
},
{
"id": 59,
"input": "def process_kwargs(**kwargs):\n if 'debug' in kwargs:\n print('Debug mode is on')",
"output": "Checks for the presence of a 'debug' key in keyword arguments."
},
{
"id": 60,
"input": "with open('log.txt', 'a') as f:\n f.write('App started\\n')",
"output": "Opens 'log.txt' in append mode and writes a new line."
},
{
"id": 61,
"input": "def get_first_item(lst):\n return lst[0] if lst else None",
"output": "Returns the first item of a list, or None if the list is empty."
},
{
"id": 62,
"input": "nums = [1, 2, 3]\ndoubled = [n * 2 for n in nums]",
"output": "Creates a new list where each element is doubled (list comprehension)."
},
{
"id": 63,
"input": "try:\n value = int('abc')\nexcept ValueError:\n value = 0",
"output": "Handles a 'ValueError' when trying to convert a non-numeric string to an integer."
},
{
"id": 64,
"input": "import json\ndata = {'key': 'value'}\njson_str = json.dumps(data)",
"output": "Converts a Python dictionary into a JSON formatted string."
},
{
"id": 65,
"input": "while True:\n user_input = input('Exit? (y/n): ')\n if user_input.lower() == 'y':\n break",
"output": "An infinite loop that breaks only when the user enters 'y'."
},
{
"id": 66,
"input": "list1 = [1, 2]\nlist2 = [3, 4]\ncombined = list1 + list2",
"output": "Concatenates two lists using the '+' operator."
},
{
"id": 67,
"input": "def filter_long_words(words, min_len):\n return [w for w in words if len(w) >= min_len]",
"output": "Filters a list of words, keeping only those longer than 'min_len'."
},
{
"id": 68,
"input": "class Parent:\n def method(self):\n return 'Parent method'\nclass Child(Parent):\n pass",
"output": "A class 'Child' that inherits all methods and properties from 'Parent'."
},
{
"id": 69,
"input": "text = '123_abc'\nif text.isalnum():\n print('Alphanumeric')",
"output": "Checks if all characters in the string are alphanumeric (not including underscore)."
},
{
"id": 70,
"input": "def power_of_two(n):\n return 2 ** n",
"output": "Calculates 2 raised to the power of 'n'."
},
{
"id": 71,
"input": "def get_last_element(lst):\n return lst[-1]",
"output": "Returns the last element of a list using a negative index."
},
{
"id": 72,
"input": "user = {'name': 'Bob'}\nuser.update({'age': 40})",
"output": "Adds or updates key-value pairs in the dictionary."
},
{
"id": 73,
"input": "import re\nmatch = re.search(r'\\d+', 'abc123xyz')",
"output": "Searches for the first occurrence of one or more digits using regex."
},
{
"id": 74,
"input": "numbers = [1, 2, 3]\nnumbers.clear()",
"output": "Removes all items from the 'numbers' list."
},
{
"id": 75,
"input": "def calculate_discount(price, rate=0.1):\n return price * (1 - rate)",
"output": "Calculates the final price after applying a default discount rate."
},
{
"id": 76,
"input": "my_tuple = (1, 2)\nif 1 in my_tuple:\n print('1 is present')",
"output": "Checks for the existence of an element within the tuple."
},
{
"id": 77,
"input": "def calculate_length(iterable):\n count = 0\n for _ in iterable:\n count += 1\n return count",
"output": "Calculates the length of an iterable manually without using 'len()'."
},
{
"id": 78,
"input": "data = [1, 2, 3, 4, 5]\nsubset = data[1:4]",
"output": "Slices the list to get a subset from index 1 up to (but not including) 4."
},
{
"id": 79,
"input": "def validate_email(email):\n return '@' in email and '.' in email",
"output": "A simple check to see if a string contains '@' and '.' for email validation."
},
{
"id": 80,
"input": "class StaticDemo:\n @staticmethod\n def helper_method(x):\n return x + 1",
"output": "A class method that can be called without instantiating the class."
},
{
"id": 81,
"input": "temp_c = 25\ntemp_f = (temp_c * 9/5) + 32",
"output": "Converts a temperature from Celsius to Fahrenheit."
},
{
"id": 82,
"input": "def is_even(n):\n return n % 2 == 0",
"output": "Checks if an integer 'n' is divisible by 2 (even)."
},
{
"id": 83,
"input": "text = 'One two three'\nwords = text.split()",
"output": "Splits a string into a list of words using whitespace as a delimiter."
},
{
"id": 84,
"input": "def counter():\n i = 0\n while True:\n yield i\n i += 1",
"output": "An infinite generator that yields incrementing integer values."
},
{
"id": 85,
"input": "import time\ntime.sleep(1)",
"output": "Pauses the execution of the program for 1 second."
},
{
"id": 86,
"input": "numbers = [10, 20, 30]\nindex = numbers.index(20)",
"output": "Finds the index of the value 20 in the list."
},
{
"id": 87,
"input": "def check_user(user):\n if user is None:\n return 'Guest'\n return user",
"output": "Returns 'Guest' if the 'user' variable is None, otherwise returns the user."
},
{
"id": 88,
"input": "data = [1, 2, 3]\nduplicate = data.copy()",
"output": "Creates a shallow copy of the list."
},
{
"id": 89,
"input": "def count_vowels(s):\n return sum(1 for char in s if char in 'aeiou')",
"output": "Counts the total number of vowels in the input string 's'."
},
{
"id": 90,
"input": "class Circle:\n def __init__(self, radius):\n self.radius = radius\n def get_area(self):\n return 3.14 * self.radius ** 2",
"output": "A class 'Circle' with a method to calculate the area."
},
{
"id": 91,
"input": "def swap(a, b):\n return b, a",
"output": "Swaps the values of two variables using tuple unpacking."
},
{
"id": 92,
"input": "my_set = {1, 2, 3}\nif 4 not in my_set:\n print('4 not in set')",
"output": "Checks if an element is not present in the set."
},
{
"id": 93,
"input": "def combine_dicts(d1, d2):\n return {**d1, **d2}",
"output": "Merges two dictionaries using the dictionary unpacking operator."
},
{
"id": 94,
"input": "with open('temp.txt', 'w') as f:\n f.write('Temporary data')",
"output": "Creates and writes 'Temporary data' to 'temp.txt' and closes the file."
},
{
"id": 95,
"input": "def get_full_name(first, last):\n return f'{first} {last}'",
"output": "Returns a full name by combining first and last names (f-string)."
},
{
"id": 96,
"input": "import random\nnames = ['a', 'b', 'c']\nwinner = random.choice(names)",
"output": "Randomly selects one element from the list 'names'."
},
{
"id": 97,
"input": "numbers = [1, 2, 3]\ndecimal = 4.5\nnumbers.append(decimal)",
"output": "Appends a floating-point number to the end of an integer list."
},
{
"id": 98,
"input": "text = 'HELLO'\nlowercase = text.lower()",
"output": "Converts the entire string to lowercase."
},
{
"id": 99,
"input": "def my_func():\n x = 10\n def inner_func():\n nonlocal x\n x = 20\n inner_func()\n return x",
"output": "Modifies a variable in the nearest enclosing scope (nonlocal)."
},
{
"id": 100,
"input": "while True:\n try:\n num = int(input('Enter num: '))\n break\n except ValueError:\n print('Invalid input')",
"output": "Repeats input prompt until a valid integer is entered."
},
{
"id": 101,
"input": "from decimal import Decimal\nresult = Decimal('0.1') + Decimal('0.2')",
"output": "Performs precise decimal arithmetic using the 'Decimal' type."
},
{
"id": 102,
"input": "def divide(a, b):\n if b == 0:\n raise ValueError('Cannot divide by zero')\n return a / b",
"output": "Raises a 'ValueError' exception if the divisor is zero."
},
{
"id": 103,
"input": "data = [('a', 1), ('b', 2)]\nmy_dict = dict(data)",
"output": "Converts a list of key-value tuples into a dictionary."
},
{
"id": 104,
"input": "nums = [1, 2, 3]\nproduct = 1\nfor num in nums:\n product *= num",
"output": "Calculates the product of all elements in the list."
},
{
"id": 105,
"input": "class MyClass:\n @classmethod\n def create_obj(cls, value):\n return cls(value)",
"output": "A method that is bound to the class and receives the class itself as the first argument."
},
{
"id": 106,
"input": "def log_time(func):\n import time\n def wrapper(*args, **kwargs):\n start = time.time()\n result = func(*args, **kwargs)\n end = time.time()\n print(f'Time: {end - start}')\n return result\n return wrapper",
"output": "A decorator that measures and logs the execution time of a function."
},
{
"id": 107,
"input": "numbers = [10, 20, 30, 40]\nlast_two = numbers[-2:]",
"output": "Gets the last two elements of the list using negative slicing."
},
{
"id": 108,
"input": "def get_square(x):\n return x * x\nresult = get_square(5)",
"output": "A simple function that returns the square of its input."
},
{
"id": 109,
"input": "def check_empty(data):\n return not data",
"output": "Checks if an iterable (list, string, etc.) is empty (truthiness)."
},
{
"id": 110,
"input": "my_set = {1, 2, 3}\nmy_set.remove(2)",
"output": "Removes the element 2 from the set (raises KeyError if not found)."
},
{
"id": 111,
"input": "import requests\nresponse = requests.get('http://api.com')",
"output": "Makes an HTTP GET request to a specified URL."
},
{
"id": 112,
"input": "def custom_sort(item):\n return item['key']\ndata = [{'key': 3}, {'key': 1}]\ndata.sort(key=custom_sort)",
"output": "Sorts a list of dictionaries based on the value of the 'key' field."
},
{
"id": 113,
"input": "text = 'hello'\nif text.endswith('o'):\n print('Ends with o')",
"output": "Checks if the string 'text' ends with the letter 'o'."
},
{
"id": 114,
"input": "def check_type(data):\n if isinstance(data, list):\n print('Is a list')",
"output": "Checks if the variable 'data' is an instance of the 'list' class."
},
{
"id": 115,
"input": "a, b, *rest = [1, 2, 3, 4, 5]",
"output": "Unpacks the first two elements and assigns the rest to a list 'rest'."
},
{
"id": 116,
"input": "try:\n # code that might fail\n pass\nexcept:\n print('An unknown error occurred')",
"output": "A general exception handler that catches all errors."
},
{
"id": 117,
"input": "def generate_sequence():\n yield 1\n yield 2",
"output": "A generator function that yields two distinct values."
},
{
"id": 118,
"input": "data = [1, 2, 3]\nreversed_data = list(reversed(data))",
"output": "Reverses the order of elements in the list."
},
{
"id": 119,
"input": "def absolute_value(n):\n return abs(n)",
"output": "Returns the absolute (non-negative) value of a number."
},
{
"id": 120,
"input": "def check_all_true(bools):\n return all(bools)",
"output": "Checks if all elements in an iterable are truthy."
},
{
"id": 121,
"input": "text = 'one,two,three'\nparts = text.split(',')",
"output": "Splits a string by a comma delimiter."
},
{
"id": 122,
"input": "user = {'name': 'Alice'}\nname = user.pop('name')",
"output": "Removes the 'name' key from the dict and returns its value."
},
{
"id": 123,
"input": "for i in range(10):\n if i % 3 == 0:\n continue",
"output": "Skips printing numbers that are divisible by 3."
},
{
"id": 124,
"input": "def count_up_to(n):\n for i in range(1, n + 1):\n print(i)",
"output": "Iterates and prints integers from 1 up to 'n' (inclusive)."
},
{
"id": 125,
"input": "import datetime\ntoday = datetime.date.today()",
"output": "Gets the current date (year, month, day)."
},
{
"id": 126,
"input": "data = [1, 2, 3]\ndata.insert(0, 0)",
"output": "Inserts the value 0 at the beginning of the list."
},
{
"id": 127,
"input": "def dict_from_list(keys, value=None):\n return dict.fromkeys(keys, value)",
"output": "Creates a dictionary with keys from a list and an optional default value."
},
{
"id": 128,
"input": "def print_type(data):\n print(type(data))",
"output": "Prints the data type of the input variable."
},
{
"id": 129,
"input": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
"output": "Calculates the factorial of 'n' using recursion."
},
{
"id": 130,
"input": "text = 'hello world'\nif 'world' in text:\n print('Found')",
"output": "Checks if the substring 'world' is present in the string 'text'."
},
{
"id": 131,
"input": "def max_of_two(a, b):\n return max(a, b)",
"output": "Returns the larger of two given numbers."
},
{
"id": 132,
"input": "class Counted:\n count = 0\n def __init__(self):\n Counted.count += 1",
"output": "A class that tracks the number of its instances using a class variable."
},
{
"id": 133,
"input": "numbers = [1, 2, 3, 4]\nfiltered = list(filter(lambda x: x > 2, numbers))",
"output": "Uses 'filter' with a 'lambda' to keep only numbers greater than 2."
},
{
"id": 134,
"input": "def repeat_string(s, n):\n return s * n",
"output": "Repeats a string 'n' times using the multiplication operator."
},
{
"id": 135,
"input": "def default_list(val, size):\n return [val] * size",
"output": "Creates a list of a specified size, initialized with a single value."
},
{
"id": 136,
"input": "my_set = {1, 2}\nmy_set.discard(3)",
"output": "Removes an element if present, without raising an error if it's missing."
},
{
"id": 137,
"input": "def get_index(lst, val):\n try:\n return lst.index(val)\n except ValueError:\n return -1",
"output": "Safely finds the index of a value or returns -1 if not found."
},
{
"id": 138,
"input": "import itertools\nperms = list(itertools.permutations([1, 2]))",
"output": "Generates all possible permutations of the elements in a list."
},
{
"id": 139,
"input": "def count_args(*args):\n return len(args)",
"output": "Returns the number of positional arguments passed to the function."
},
{
"id": 140,
"input": "data = {'a': 1}\ndata['b'] = 2",
"output": "Adds a new key-value pair to the dictionary."
},
{
"id": 141,
"input": "text = ' leading whitespace'\nno_leading = text.lstrip()",
"output": "Removes only the leading whitespace from the string."
},
{
"id": 142,
"input": "def check_any_true(bools):\n return any(bools)",
"output": "Checks if at least one element in an iterable is truthy."
},
{
"id": 143,
"input": "list1 = [1, 2]\nlist2 = list1",
"output": "Assigns a reference to 'list1' to 'list2' (no copy is made)."
},
{
"id": 144,
"input": "def greet_user(user_name):\n print(f'Welcome, {user_name}')",
"output": "Prints a simple welcome message using a formatted string."
},
{
"id": 145,
"input": "def sum_list(lst):\n return sum(lst)",
"output": "Calculates the sum of all numeric elements in a list."
},
{
"id": 146,
"input": "import random\nrandom.shuffle(my_list)",
"output": "Shuffles the list elements randomly (in-place modification)."
},
{
"id": 147,
"input": "class NamedObject:\n def __repr__(self):\n return f'<NamedObject name={self.name}>'",
"output": "Defines the object's string representation for debugging and logging."
},
{
"id": 148,
"input": "for i in range(5):\n print('Looping...')\nelse:\n print('Loop finished')",
"output": "Prints a message after a for loop completes normally (without a break)."
},
{
"id": 149,
"input": "def flatten_dict(d):\n return [(k, v) for k, v in d.items()]",
"output": "Converts a dictionary into a list of key-value tuples."
},
{
"id": 150,
"input": "text = 'Python'\nmiddle = text[1:-1]",
"output": "Gets a substring from the second character up to the second to last character."
},
{
"id": 151,
"input": "def check_negative(n):\n return n < 0",
"output": "Checks if a number is negative."
},
{
"id": 152,
"input": "def get_tuple_size(t):\n return len(t)",
"output": "Returns the number of elements in a tuple."
},
{
"id": 153,
"input": "data = [1, 2, 3]\nvalue = data.pop()",
"output": "Removes and returns the last element of the list."
},
{
"id": 154,
"input": "import time\nstart = time.time()\n# ...\nend = time.time()\nduration = end - start",
"output": "Measures the duration of a code block using 'time.time()'."
},
{
"id": 155,
"input": "text = 'hello'\nif text.isupper():\n print('Uppercase')",
"output": "Checks if all characters in the string are uppercase."
},
{
"id": 156,
"input": "def set_intersection(s1, s2):\n return s1 & s2",
"output": "Calculates the intersection of two sets using the '&' operator."
},
{
"id": 157,
"input": "def print_var_info(*args):\n print(f'Count: {len(args)}')",
"output": "Prints the count of positional arguments passed to the function."
},
{
"id": 158,
"input": "my_dict = {'a': 1}\nmy_dict.setdefault('b', 2)",
"output": "Gets the value for key 'b' or sets it to 2 if missing."
},
{
"id": 159,
"input": "import re\nresult = re.match(r'^start', 'starting point')",
"output": "Checks if the string begins with 'start' using regex matching."
},
{
"id": 160,
"input": "def is_divisible(a, b):\n return a % b == 0",
"output": "Checks if number 'a' is perfectly divisible by number 'b'."
},
{
"id": 161,
"input": "temp = 40\ntemp_type = 'C' if temp < 100 else 'H'",
"output": "Assigns a value based on a condition using a ternary operator."
},
{
"id": 162,
"input": "data = [1, 2, 3]\nfor item in data:\n if item == 2:\n continue\n print(item)",
"output": "Iterates over a list, skipping the element '2'."
},
{
"id": 163,
"input": "from datetime import timedelta\ndelta = timedelta(days=1)",
"output": "Creates a time difference object representing one day."
},
{
"id": 164,
"input": "def get_default_dict(key, default_dict):\n return default_dict.get(key)",
"output": "Retrieves a value from a dictionary using the safe 'get' method."
},
{
"id": 165,
"input": "names = ['a', 'b', 'c']\nfor name in names:\n if name == 'b':\n print('Found b')\n break",
"output": "Searches for 'b' in a list and stops the loop when found."
},
{
"id": 166,
"input": "def check_falsy(data):\n return not bool(data)",
"output": "Checks if the data structure or variable is falsy (empty, zero, None, etc.)."
},
{
"id": 167,
"input": "class MyClass:\n def __init__(self, value):\n self._value = value",
"output": "Initializes a class instance with a private-like attribute '_value'."
},
{
"id": 168,
"input": "def calculate_remainder(a, b):\n return a % b",
"output": "Calculates the remainder of division of 'a' by 'b' (modulo operation)."
},
{
"id": 169,
"input": "data = [1, 2, 3]\ndata.reverse()",
"output": "Reverses the list in-place."
},
{
"id": 170,
"input": "def combine_sets(s1, s2):\n return s1 | s2",
"output": "Calculates the union of two sets using the '|' operator."
},
{
"id": 171,
"input": "def print_global():\n global my_var\n print(my_var)",
"output": "Accesses a global variable 'my_var' from within a function."
},
{
"id": 172,
"input": "text = '12345'\nif text.isdigit():\n print('All digits')",
"output": "Checks if the string contains only digits."
},
{
"id": 173,
"input": "def create_tuple(a, b):\n return a, b",
"output": "Returns two variables as a tuple implicitly."
},
{
"id": 174,
"input": "import os\nif os.path.exists('file.txt'):\n print('File exists')",
"output": "Checks if a file or directory at the specified path exists."
},
{
"id": 175,
"input": "def filter_non_numeric(lst):\n return [x for x in lst if isinstance(x, (int, float))]",
"output": "Filters a list, keeping only integer and float types (numeric values)."
},
{
"id": 176,
"input": "from collections import namedtuple\nPoint = namedtuple('Point', ['x', 'y'])",
"output": "Defines a custom tuple type with named fields 'x' and 'y'."
},
{
"id": 177,
"input": "def unpack_tuple_with_star(t):\n a, *rest = t\n return rest",
"output": "Unpacks the first element of a tuple, assigning the rest to a list using '*'."
},
{
"id": 178,
"input": "def sort_list_by_key(lst, key_func):\n return sorted(lst, key=key_func)",
"output": "Sorts a list using a custom function to determine the sort key."
},
{
"id": 179,
"input": "d1 = {'a': 1}\nd2 = {'b': 2}\nd3 = d1.copy()\nd3.update(d2)",
"output": "Copies one dictionary and updates it with key-value pairs from another."
},
{
"id": 180,
"input": "def loop_for_n(n):\n for i in range(n):\n print(i)",
"output": "A simple for loop that iterates 'n' times starting from 0."
},
{
"id": 181,
"input": "text = 'hello world'\ntext.count('l')",
"output": "Counts the number of occurrences of the character 'l' in the string."
},
{
"id": 182,
"input": "def get_exponent(a, b):\n return pow(a, b)",
"output": "Calculates 'a' raised to the power of 'b' using the built-in 'pow' function."
},
{
"id": 183,
"input": "try:\n pass\nfinally:\n print('Cleanup done')",
"output": "Executes the 'finally' block regardless of whether an exception occurred or not."
},
{
"id": 184,
"input": "def check_in_range(n, min_val, max_val):\n return min_val <= n <= max_val",
"output": "Checks if a number 'n' is within a specified inclusive range."
},
{
"id": 185,
"input": "def print_only_kwargs(*, a, b):\n print(a, b)",
"output": "Function where 'a' and 'b' must be passed as keyword arguments only."
},
{
"id": 186,
"input": "def filter_by_length(words, length):\n return list(filter(lambda w: len(w) == length, words))",
"output": "Filters a list of words to include only those of a specific length using 'filter'."
},
{
"id": 187,
"input": "data = [1, 2, 3]\nlist_copy = data[:]",
"output": "Creates a shallow copy of the list using full slicing."
},
{
"id": 188,
"input": "text = 'abc_def'\ntext.split('_')",
"output": "Splits the string into a list using the underscore '_' as a separator."
},
{
"id": 189,
"input": "def make_set(lst):\n return set(lst)",
"output": "Converts a list into a set, removing duplicate elements."
},
{
"id": 190,
"input": "class Base:\n def __init__(self, val):\n self.val = val\nclass Derived(Base):\n def __init__(self, val):\n super().__init__(val)",
"output": "A derived class correctly calling the base class's constructor using 'super()'."
},
{
"id": 191,
"input": "def print_items_and_index(lst):\n for i, item in enumerate(lst):\n print(f'{i}: {item}')",
"output": "Iterates over a list, printing both the index and the item."
},
{
"id": 192,
"input": "def is_title_case(s):\n return s.istitle()",
"output": "Checks if a string is in title case."
},
{
"id": 193,
"input": "data = [1, 2, 3]\ndata.insert(len(data), 4)",
"output": "Inserts the value 4 at the end of the list (same as append)."
},
{
"id": 194,
"input": "def get_dict_values(d):\n return list(d.values())",
"output": "Returns a list of all values contained in the dictionary."
},
{
"id": 195,
"input": "import re\ntext = '12 apples'\nnum = re.search(r'\\d+', text).group(0)",
"output": "Extracts the first sequence of digits from the string using regex search."
},
{
"id": 196,
"input": "def check_value_type(data):\n if isinstance(data, (int, str)):\n print('Int or String')",
"output": "Checks if a variable is an instance of either 'int' or 'str' type."
},
{
"id": 197,
"input": "def loop_with_while(condition):\n while condition:\n break",
"output": "A while loop that immediately terminates using 'break'."
},
{
"id": 198,
"input": "def generate_cubes(n):\n return (i**3 for i in range(n))",
"output": "Returns a generator expression for the cubes of numbers up to 'n'."
},
{
"id": 199,
"input": "data = {'x': 1, 'y': 2}\nfor key, val in data.items():\n print(f'{key}={val}')",
"output": "Iterates over and prints both keys and values of the dictionary."
},
{
"id": 200,
"input": "def calculate_sum_of_squares(n):\n return sum(i**2 for i in range(1, n+1))",
"output": "Calculates the sum of the squares of numbers from 1 up to 'n'."