← 목록

Synth · CodeAlpaca일부

총 20,022개 · 페이지 650/668
🔀 랜덤
불러오는 중…

[output] | def sortString(string): words = string.split(" ") sortedWords = [word for word in words] for i in range(len(sortedWords)): sortedWords[i] = "".join(sorted(sortedWords[i])) return " ".join(sortedWords) print(sortString("zebra cat dog")) OUTPUT: abcerz cdgot [instruction] | Design a function 'sortString' which takes a string of words and sorts each word alphabetically. [input] | string = "zebra cat dog"

[output] | def divideList(list, n): nList = [[] for _ in range(n)] for item in list: nList[item % n].append(item) return nList print(divideList([1, 2, 3, 4, 5], 2)) OUTPUT: [[1, 3, 5], [2, 4]] [instruction] | Write a function 'divideList' which takes a list and an integer, and divides the list into n groups. [input] | list = [1, 2, 3, 4, 5] n = 2

[output] | def hasRepeats(list): for i in range(len(list)): for j in range(i+1, len(list)): if list[i] == list[j]: return True return False print(hasRepeats([1, 3, 9, 5, 3])) OUTPUT: True [instruction] | Write a function 'hasRepeats' that checks if a list has two of the same elements. [input] | list = [1, 3, 9, 5, 3]

[output] | function formatDate(date) { let newDate = date.substr(0, 4) + "/" + date.substr(4, 2) + "/" + date.substr(6); return newDate; } console.log(formatDate("20210320")) OUTPUT: 03/20/2021 [instruction] | Write a JavaScript function 'formatDate' which takes a date as string in the format "YYYYMMDD" and returns it in the format "MM/DD/YYYY" [input] | date = "20210320"

[output] | int removeDuplicates(int arr[], int n) { int j = 0; for (int i=0; i<n-1; i++){ if (arr[i] == arr[i+1]) continue; else arr[j++] = arr[i]; } arr[j++] = arr[n-1]; return j; } [instruction] | Design a C++ function 'removeDuplicates' to remove all duplicate elements from an array and return the new length of the array. [input] | arr = [1, 3, 1, 5, 5]

[output] | x = 0 y = 1 y = x [instruction] | Create two variables x and y with values 0 and 1 respectively and assign x to y using the arithmetic operators. [input] |

[output] | let result = arr.filter(str => str[0] === 'A' && str.length === 5); [instruction] | Write a JavaScript code to filter an array of strings that begin with the letter `A` and have a length of 5. [input] | let arr = ["Apple", "Banana", "Ant", "Cat", "Arson"];

[output] | student_marks = { "Ann": 78, "John": 92, "Bob": 67 } [instruction] | Create a Python dictionary with the student's name as the key and marks as the value. [input] | data = { "Ann": 78, "John": 92, "Bob": 67 }

[output] | String hash = MessageDigest.getInstance("SHA-1").digest(password.getBytes(StandardCharsets.UTF_8)); [instruction] | Write a Java code to encrypt a password using `sha1` hash. [input] | String password = "password123";

[output] | .main-div { background-color: blue; } [instruction] | Create a `CSS` rule to change the background color of a div element with the class name `main-div` to blue. [input] |

[output] | SELECT name, department FROM employees WHERE hire_date > '2020-01-01'; [instruction] | Write an `SQL` query to select the empoloyee's name and department who were hired after `Jan 2020`. [input] |

[output] | from bs4 import BeautifulSoup # data stored in a string html_doc = """ <html><head><title>Parser Demo</title></head> <body> <h1>This is Heading1</h1> <h2>This is Heading2</h2> </body></html> """ # passing the html document to # BeautifulSoup() for parsing soup = BeautifulSoup(html_do [instruction] | Write a `Python` program to parse an HTML document and store the tags in a list. [input] |

[output] | let arr = [19, 18, 17, 16, 15, 14, 13, 12, 11, 10]; [instruction] | Create a `JavaScript` array containing 10 numbers from 10 to 19 in reverse order. [input] |

[output] | function sortByValue($data) { asort($data); return $data; } [instruction] | Write a `PHP` script to sort an associative array based on its values. [input] | $data = array("John"=>45, "Bob"=>67, "Ann"=>55);

[output] | sum = 164 [instruction] | Write an operation that adds all the numbers in a given list. [input] | [32, 15, 45, 56, 16]

[output] | def binary_to_decimal(binary): decimal = 0 length = len(binary) for digit in range(0, length): decimal += int(binary[digit]) * pow(2, length - digit - 1) return decimal print(binary_to_decimal("60")) Output: 24 [instruction] | Implement a function that can convert a number from one number system to another. [input] | Input: The number 60 in binary to be converted to decimal.

[output] | list_numbers = [i for i in range(1,101)] [instruction] | Initialize a variable with a list containing numbers from 1-100. [input] |

[output] | SELECT * FROM movies WHERE year = 2019; [instruction] | Generate a SQL query to retrieve a list of all the movies released in 2019. [input] |

[output] | seconds = 14 * 60 * 60 print(seconds) Output: 50400 seconds [instruction] | Write a code to calculate how many seconds are in 14 hours. [input] |

[output] | def summarize_text(text): # Split the text into sentences sentences = text.split('.') # Compute the frequency of each sentence sentence_frequencies = {} for sent in sentences: # Clean the sentences clean_sent = sent.strip().lower() # Count the freq [instruction] | Design an algorithm to summarize a long text. [input] |

[output] | 5 / \ 4 11 / \ / \ N 6 10 8 [instruction] | Design a binary search tree that has the following values in the given order - 5, 4, 11, 6, 10, 8. [input] |

[output] | def remove_punctuation(string): return string.replace(' ', '').replace(',', '').replace('!', '') [instruction] | Given a string, create a method to remove all empty spaces and punctuation from the string. [input] | "Hello, world !"

[output] | def shortest_word(arr): shortest_word = arr[0] for word in arr[1:]: if len(word) < len(shortest_word): shortest_word = word return shortest_word [instruction] | Create a method to find the shortest word in a given array of strings. [input] |

[output] | SELECT DISTINCT quantity FROM Orders [instruction] | Write a query to find all unique numbers in the column 'quantity' from the database table 'Orders'. [input] |

[output] | def capitalize_words(string): return ' '.join(word.capitalize() for word in string.split()) [instruction] | Given a sentence, create a method to capitalize every word in the sentence. [input] | hello world

[output] | function roundNumber(x) { return Math.round(x); } [instruction] | Edit the following JavaScript code so that it rounds a number to the nearest integer. [input] | function roundNumber(x) { return x + 0.5; }

[output] | def say_thanks(): for i in range(3): print("Thank you") [instruction] | Write a function to output "Thank you" three times. [input] |

[output] | The minimum number of arguments needed to call the function "foo" is 0. [instruction] | What is the minimum number of arguments needed to call the function "foo". [input] |

[output] | pip install numpy [instruction] | Install Numpy in Python using pip. [input] |

[output] | javac Example.java [instruction] | Compile a Java class named "Example". [input] |

← → 방향키로 페이지 이동 · 숫자 입력 후 Enter로 점프