question_id
int64 1.48k
42.8M
| intent
stringlengths 11
122
| rewritten_intent
stringlengths 4
183
⌀ | snippet
stringlengths 2
232
|
---|---|---|---|
21,261,330 | Splitting string and removing whitespace Python | Split string with comma (,) and remove whitespace from a string 'my_string' | [item.strip() for item in my_string.split(',')] |
6,886,493 | Get all object attributes | Get all object attributes of object `obj` | print((obj.__dict__)) |
6,886,493 | Get all object attributes | Get all object attributes of an object | dir() |
6,886,493 | Get all object attributes | Get all object attributes of an object | dir() |
16,389,188 | How to center a window with PyGObject | pygobject center window `window` | window.set_position(Gtk.WindowPosition.CENTER) |
14,159,753 | how to change the size of the sci notation above the y axis in matplotlib? | change the size of the sci notation to '30' above the y axis in matplotlib `plt` | plt.rc('font', **{'size': '30'}) |
29,530,232 | Python pandas: check if any value is NaN in DataFrame | check if datafram `df` has any NaN vlaues | df.isnull().values.any() |
4,979,542 | Python - use list as function parameters | unpack the arguments out of list `params` to function `some_func` | some_func(*params) |
9,880,173 | How to decode encodeURIComponent in GAE (python)? | decode encodeuricomponent in GAE | urllib.parse.unquote(h.path.encode('utf-8')).decode('utf-8') |
41,178,532 | Percentage match in pandas Dataframe | get proportion of rows in dataframe `trace_df` whose values for column `ratio` are greater than 0 | (trace_df['ratio'] > 0).mean() |
8,704,952 | How to convert a tuple to a string in Python? | convert a set of tuples `queryresult` to a string `emaillist` | emaillist = '\n'.join(item[0] for item in queryresult) |
8,704,952 | How to convert a tuple to a string in Python? | convert a set of tuples `queryresult` to a list of strings | [item[0] for item in queryresult] |
8,704,952 | How to convert a tuple to a string in Python? | convert a list of tuples `queryresult` to a string from the first indexes. | emaillist = '\n'.join([item[0] for item in queryresult]) |
27,867,754 | Python get focused entry name | get the widget which has currently the focus in tkinter instance `window2` | print(('focus object class:', window2.focus_get().__class__)) |
36,113,747 | How to declare an array in python | Initialize a list `a` with `10000` items and each item's value `0` | a = [0] * 10000 |
7,794,208 | How can I remove duplicate words in a string with Python? | Keep only unique words in list of words `words` and join into string | print(' '.join(sorted(set(words), key=words.index))) |
13,628,725 | How to generate random numbers that are different? | generate 6 random numbers between 1 and 50 | random.sample(range(1, 50), 6) |
13,628,725 | How to generate random numbers that are different? | generate six unique random numbers in the range of 1 to 49. | random.sample(range(1, 50), 6) |
764,235 | Dictionary to lowercase in Python | lowercase keys and values in dictionary `{'My Key': 'My Value'}` | {k.lower(): v.lower() for k, v in list({'My Key': 'My Value'}.items())} |
764,235 | Dictionary to lowercase in Python | lowercase all keys and values in dictionary `{'My Key': 'My Value'}` | dict((k.lower(), v) for k, v in {'My Key': 'My Value'}.items()) |
764,235 | Dictionary to lowercase in Python | Convert each key,value pair in a dictionary `{'My Key': 'My Value'}` to lowercase | dict((k.lower(), v.lower()) for k, v in {'My Key': 'My Value'}.items()) |
34,197,047 | sorting list of list in python | sorting the lists in list of lists `data` | [sorted(item) for item in data] |
7,831,371 | Is there a way to get a list of column names in sqlite? | SQLite get a list of column names from cursor object `cursor` | names = list(map(lambda x: x[0], cursor.description)) |
3,283,306 | finding out absolute path to a file from python | get the absolute path of a running python script | os.path.abspath(__file__) |
2,173,797 | how to sort 2d array by row in python? | sort 2d array `matrix` by row with index 1 | sorted(matrix, key=itemgetter(1)) |
7,658,932 | Finding index of the same elements in a list | Get all indexes of a letter `e` from a string `word` | [index for index, letter in enumerate(word) if letter == 'e'] |
8,901,996 | How to print container object with unicode-containing values? | decode utf-8 code `x` into a raw unicode literal | print(str(x).decode('raw_unicode_escape')) |
464,736 | Python regular expressions - how to capture multiple groups from a wildcard expression? | split string 'abcdefg' into a list of characters | re.findall('\\w', 'abcdefg') |
82,831 | check whether a file exists | check whether a file `fname` exists | os.path.isfile(fname) |
82,831 | check whether a file exists | check whether file "/path/to/file" exists | my_file = Path('/path/to/file')
if my_file.is_file():
pass |
82,831 | check whether a file exists | check whether file `file_path` exists | os.path.exists(file_path) |
82,831 | check whether a file exists | check whether a file "/etc/password.txt" exists | print(os.path.isfile('/etc/password.txt')) |
82,831 | check whether a file exists | check whether a file "/etc" exists | print(os.path.isfile('/etc')) |
82,831 | check whether a file exists | check whether a path "/does/not/exist" exists | print(os.path.exists('/does/not/exist')) |
82,831 | check whether a file exists | check whether a file "/does/not/exist" exists | print(os.path.isfile('/does/not/exist')) |
82,831 | check whether a file exists | check whether a path "/etc" exists | print(os.path.exists('/etc')) |
82,831 | check whether a file exists | check whether a path "/etc/password.txt" exists | print(os.path.exists('/etc/password.txt')) |
1,059,559 | Split Strings with Multiple Delimiters? | split string "a;bcd,ef g" on delimiters ';' and ',' | """a;bcd,ef g""".replace(';', ' ').replace(',', ' ').split() |
41,127,441 | Why can you loop through an implicit tuple in a for loop, but not a comprehension in Python? | get a list each value `i` in the implicit tuple `range(3)` | list(i for i in range(3)) |
20,347,766 | Pythonically add header to a csv file | add field names as headers in csv constructor `writer` | writer.writeheader() |
18,500,541 | How to flatten a tuple in python | flatten a tuple `l` | [(a, b, c) for a, (b, c) in l] |
7,253,907 | Python - how to convert int to string represent a 32bit Hex number | convert 3652458 to string represent a 32bit hex number | """0x{0:08X}""".format(3652458) |
674,519 | How can I convert a Python dictionary to a list of tuples? | convert a python dictionary `d` to a list of tuples | [(v, k) for k, v in list(d.items())] |
674,519 | How can I convert a Python dictionary to a list of tuples? | convert dictionary of pairs `d` to a list of tuples | [(v, k) for k, v in d.items()] |
674,519 | How can I convert a Python dictionary to a list of tuples? | convert python 2 dictionary `a` to a list of tuples where the value is the first tuple element and the key is the second tuple element | [(v, k) for k, v in a.items()] |
674,519 | How can I convert a Python dictionary to a list of tuples? | convert a python dictionary 'a' to a list of tuples | [(k, v) for k, v in a.items()] |
2,397,687 | What's the easiest way to convert a list of hex byte strings to a list of hex integers? | convert a list of hex byte strings `['BB', 'A7', 'F6', '9E']` to a list of hex integers | [int(x, 16) for x in ['BB', 'A7', 'F6', '9E']] |
2,397,687 | What's the easiest way to convert a list of hex byte strings to a list of hex integers? | convert the elements of list `L` from hex byte strings to hex integers | [int(x, 16) for x in L] |
961,263 | Two values from one input in python? | assign values to two variables, `var1` and `var2` from user input response to `'Enter two numbers here: ` split on whitespace | var1, var2 = input('Enter two numbers here: ').split() |
34,358,278 | Django filter JSONField list of dicts | Filter a json from a key-value pair as `{'fixed_key_1': 'foo2'}` in Django | Test.objects.filter(actions__contains=[{'fixed_key_1': 'foo2'}]) |
32,292,554 | Is there a cleaner way to iterate through all binary 4-tuples? | create a list containing a four elements long tuples of permutations of binary values | itertools.product(list(range(2)), repeat=4) |
30,483,977 | Python - Get Yesterday's date as a string in YYYY-MM-DD format | get yesterday's date as a string in `YYYY-MM-DD` format using timedelta | (datetime.now() - timedelta(1)).strftime('%Y-%m-%d') |
28,253,102 | Python 3: Multiply a vector by a matrix without NumPy | Get the dot product of matrix `[1,0,0,1,0,0]` and matrix `[[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]]` | np.dot([1, 0, 0, 1, 0, 0], [[0, 1], [1, 1], [1, 0], [1, 0], [1, 1], [0, 1]]) |
23,797,491 | Parse_dates in Pandas | convert date strings in pandas dataframe column`df['date']` to pandas timestamps using the format '%d%b%Y' | df['date'] = pd.to_datetime(df['date'], format='%d%b%Y') |
4,383,571 | Importing files from different folder | Importing file `file` from folder '/path/to/application/app/folder' | sys.path.insert(0, '/path/to/application/app/folder')
import file |
20,206,615 | How can a pandas merge preserve order? | do a `left` merge of dataframes `x` and `y` on the column `state` and sort by `index` | x.reset_index().merge(y, how='left', on='state', sort=False).sort('index') |
16,436,133 | How can i create the empty json object in python | Create a default empty json object if no json is available in request parameter `mydata` | json.loads(request.POST.get('mydata', '{}')) |
2,231,663 | Slicing a list into a list of sub-lists | get a list of tuples of every three consecutive items in list `[1, 2, 3, 4, 5, 6, 7, 8, 9]` | list(zip(*((iter([1, 2, 3, 4, 5, 6, 7, 8, 9]),) * 3))) |
2,231,663 | Slicing a list into a list of sub-lists | slice list `[1, 2, 3, 4, 5, 6, 7]` into lists of two elements each | list(grouper(2, [1, 2, 3, 4, 5, 6, 7])) |
2,231,663 | Slicing a list into a list of sub-lists | null | [input[i:i + n] for i in range(0, len(input), n)] |
2,597,099 | Sorting numbers in string format with Python | Sort list `keys` based on its elements' dot-seperated numbers | keys.sort(key=lambda x: map(int, x.split('.'))) |
2,597,099 | Sorting numbers in string format with Python | Sort a list of integers `keys` where each value is in string format | keys.sort(key=lambda x: [int(y) for y in x.split('.')]) |
32,838,802 | numpy with python: convert 3d array to 2d | convert a 3d array `img` of dimensions 4x2x3 to a 2d array of dimensions 3x8 | img.transpose(2, 0, 1).reshape(3, -1) |
27,060,098 | Replacing few values in a pandas dataframe column with another value | replacing 'ABC' and 'AB' values in column 'BrandName' of dataframe `df` with 'A' | df['BrandName'].replace(['ABC', 'AB'], 'A') |
27,060,098 | Replacing few values in a pandas dataframe column with another value | replace values `['ABC', 'AB']` in a column 'BrandName' of pandas dataframe `df` with another value 'A' | df['BrandName'] = df['BrandName'].replace(['ABC', 'AB'], 'A') |
26,081,300 | Pandas: Subtract row mean from each element in row | Subtract the mean of each row in dataframe `df` from the corresponding row's elements | df.sub(df.mean(axis=1), axis=0) |
22,520,932 | Python, remove all non-alphabet chars from string | remove all non-alphabet chars from string `s` | """""".join([i for i in s if i.isalpha()]) |
6,429,638 | How to split a string into integers in Python? | split a string `s` into integers | l = (int(x) for x in s.split()) |
6,429,638 | How to split a string into integers in Python? | split a string `42 0` by white spaces. | """42 0""".split() |
6,429,638 | How to split a string into integers in Python? | null | map(int, '42 0'.split()) |
13,076,560 | Get the indexes of truthy elements of a boolean list as a list/tuple | get indexes of all true boolean values from a list `bool_list` | [i for i, elem in enumerate(bool_list, 1) if elem] |
11,391,969 | How to group pandas DataFrame entries by date in a non-unique column | group dataframe `data` entries by year value of the date in column 'date' | data.groupby(data['date'].map(lambda x: x.year)) |
32,191,029 | Getting the indices of several elements in a NumPy array at once | Get the indices in array `b` of each element appearing in array `a` | np.in1d(b, a).nonzero()[0] |
3,961,581 | In Python, how to display current time in readable format | display current time in readable format | time.strftime('%l:%M%p %z on %b %d, %Y') |
10,998,621 | Rotate axis text in python matplotlib | rotate x-axis text labels of plot `ax` 45 degrees | ax.set_xticklabels(ax.xaxis.get_majorticklabels(), rotation=45) |
25,678,689 | How does python do string magic? | append array of strings `['x', 'x', 'x']` into one string | """""".join(['x', 'x', 'x']) |
8,712,332 | Array indexing in numpy | retrieve all items in an numpy array 'x' except the item of the index 1 | x[(np.arange(x.shape[0]) != 1), :, :] |
39,605,640 | How do I pull a recurring key from a JSON? | pull a value with key 'name' from a json object `item` | print(item['name']) |
27,318,022 | Read a File from redirected stdin with python | read a file from redirected stdin and save to variable `result` | result = sys.stdin.read() |
2,416,823 | How to get the content of a Html page in Python | Get all the texts without tags from beautiful soup object `soup` | """""".join(soup.findAll(text=True)) |
17,424,182 | Extracting all rows from pandas Dataframe that have certain value in a specific column | extract all rows from dataframe `data` where the value of column 'Value' is True | data[data['Value'] == True] |
9,841,303 | Removing duplicate characters from a string | removing duplicate characters from a string variable "foo" | """""".join(set(foo)) |
930,865 | how to sort by a computed value in django | sort objects in model `Profile` based on Theirs `reputation` attribute | sorted(Profile.objects.all(), key=lambda p: p.reputation) |
25,440,008 | python pandas flatten a dataframe to a list | flatten a dataframe df to a list | df.values.flatten() |
17,734,779 | how do I sort a python list of dictionaries given a list of ids with the desired order? | sort list `users` using values associated with key 'id' according to elements in list `order` | users.sort(key=lambda x: order.index(x['id'])) |
17,734,779 | how do I sort a python list of dictionaries given a list of ids with the desired order? | sort a python list of dictionaries `users` by a given list `order` of ids 'id' with the desired order | users.sort(key=lambda x: order.index(x['id'])) |
19,069,701 | Python requests library how to pass Authorization header with single token | request URI '<MY_URI>' and pass authorization token 'TOK:<MY_TOKEN>' to the header | r = requests.get('<MY_URI>', headers={'Authorization': 'TOK:<MY_TOKEN>'}) |
1,885,181 | How do I un-escape a backslash-escaped string in python? | un-escape a backslash-escaped string in `Hello,\\nworld!` | print('"Hello,\\nworld!"'.decode('string_escape')) |
9,507,819 | Can I have a non-greedy regex with dotall? | match regex pattern 'a*?bc*?' on string 'aabcc' with DOTALL enabled | re.findall('a*?bc*?', 'aabcc', re.DOTALL) |
7,670,226 | python/numpy: how to get 2D array column length? | get second array column length of array `a` | a.shape[1] |
12,376,863 | Adding calculated column(s) to a dataframe in pandas | use operations like max/min within a row to a dataframe 'd' in pandas | d.apply(lambda row: min([row['A'], row['B']]) - row['C'], axis=1) |
8,899,905 | Count number of occurrences of a given substring in a string | count number of occurrences of a substring 'ab' in a string "abcdabcva" | """abcdabcva""".count('ab') |
25,040,875 | Get a list of values from a list of dictionaries in python | get a list of values with key 'key' from a list of dictionaries `l` | [d['key'] for d in l if 'key' in d] |
25,040,875 | Get a list of values from a list of dictionaries in python | get a list of values for key 'key' from a list of dictionaries `l` | [d['key'] for d in l] |
25,040,875 | Get a list of values from a list of dictionaries in python | get a list of values for key "key" from a list of dictionaries in `l` | [d['key'] for d in l] |
40,744,328 | How to order a list of lists by the first value | order a list of lists `l1` by the first value | l1.sort(key=lambda x: int(x[0])) |
40,744,328 | How to order a list of lists by the first value | order a list of lists `[[1, 'mike'], [1, 'bob']]` by the first value of individual list | sorted([[1, 'mike'], [1, 'bob']]) |
3,008,992 | case sensitive string replacement in Python | replace a string `Abc` in case sensitive way using maketrans | """Abc""".translate(maketrans('abcABC', 'defDEF')) |
8,519,599 | python: dictionary to string, custom format? | dictionary `d` to string, custom format | """<br/>""".join([('%s:: %s' % (key, value)) for key, value in list(d.items())]) |
22,733,642 | how to write a unicode csv in Python 2.7 | null | self.writer.writerow([str(s).encode('utf-8') for s in row]) |
Subsets and Splits