python-2.7

How can I recreate Ruby's sort_by {rand} in python?

How can I recreate Ruby's sort_by {rand} in python? Question: I have a line of code where can sort an array into random order: someArray.sort_by {rand} so in python, how can I convert to it to python code? Asked By: hanan || Source Answers: Maybe you are looking for this: import random l = [1, …

Total answers: 2

How to insert value for varbinary type data in SQL?

How to insert value for varbinary type data in SQL? Question: I have a python script that can provide some certain data in byte array, but it cannot be converted to a string (because of invisible characters). Now that I want to insert its value to a varbinary type field in a mysql database, how …

Total answers: 1

typeerror print_slow() takes 1 positional argument but 2 were given

typeerror print_slow() takes 1 positional argument but 2 were given Question: so im fiddling around in pytbon cuz im bored and i realise i try to slow print a input i have earlier in the code i bave defined slow print ive imported every thing i need but when i run it it saw its …

Total answers: 2

How to get pairwise combinations of words?

How to get pairwise combinations of words? Question: Given a string I want pair wise combinations of the words present in the string with blank spaces. For instance for the following string: string = "This is cat" I want the following output: str1 = "This is cat" str2 = "Thisis cat" str3 = "This iscat" …

Total answers: 1

How to use the find function to help replace a word in a sentence?

How to use the find function to help replace a word in a sentence? Question: I’m working on my Python homework of: Write a program that requests a sentence, a word in the sentence, and another word and then displays the sentence with the first word replaced by the second. The hint says to use …

Total answers: 2

Error : psutil.NoSuchProcess: Process no longer exists (pid=23100)

Error : psutil.NoSuchProcess: Process no longer exists (pid=23100) Question: I have this code for getting PIDs for specific processes; the code is running well, but sometimes I get this error: psutil.NoSuchProcess: Process no longer exists (pid=xxxx) How can this problem be solved? And how can I restart the script if this error or other errors …

Total answers: 1

How to create an if statement program to calculate a tip?

How to create an if statement program to calculate a tip? Question: I’m trying to write a program for my homework: Write a program to determine how much to tip the server in a restaurant. The tip should be 15% of the check, with a minimum of $2. The hint said to use an if …

Total answers: 3

How to extract values from dataframe in a complicated way

How to extract values from dataframe in a complicated way Question: I have a dataframe. I want it to filter it and reduce certain values to a string. The dataframe looks like this EXPECTED OUTPUT 42.0(1A,1B,0C) 41.0(1A,1B,0C) 43.0(0A,1B,0C) 45.0(1A,1B,0C) Code: data = [[‘42.0’, ‘A’], [‘41.0’, ‘A’], [‘43.0’, ‘B’], [‘41.0’, ‘B’], [‘42.0’, ‘B’],[‘45.0’, ‘B’],[‘45.0’, ‘A’]] df …

Total answers: 1