[Solved] How to create a python virtual environment from the command line? [duplicate]

Linux/macos: virtualenv -p python3 env source env/bin/activate pip install -r requirements.txt windows: virtualenv -p python3 env env\scripts\activate pip install -r requirements.txt if you need to specify the full path to python you can use something like virtualenv -p C:\Program Files\Python36\python.exe myvirtualenv solved How to create a python virtual environment from the command line? [duplicate]

[Solved] Python sorting a list of pairs

Here is a method to do what you are trying to achieve. unsorted = [[1, 0], [2, 0], [3, 0], [4, 2], [5, 2], [6, 5], [7, 6], [8,0]] sortList = [] sortDict = {} for x in unsorted: if x[1] != 0: if x[1] in sortDict: sortDict[x[1]].append(x[0]) else: sortDict[x[1]] = [x[0]] for x in … Read more

[Solved] Build a Parameterized SQL Statement from an array of values

I’m not sure what you expect this to do: “,”.join(u”%s”, (v,) for v in values) but the error message gives you some clue on what you’re doing wrong: SyntaxError: Generator expression must be parenthesized if not sole argument the “Generator expression” part here being (v,) for v in values. What you want is obviously something … Read more

[Solved] In Python how can I change the values in a list to meet certain criteria

Assuming the existing values don’t matter this would work def fixList(inputList, splitChar=”X”): outputList = inputList[:] x = None for i in xrange(len(outputList)): if outputList[i] == splitChar: outputList[i] = x = 0 elif x is None: continue else: outputList[i] = x x += 1 return outputList eg >>> a = [‘X’,1,2,3,4,5,6,7,8,9,’X’,11,12,13,14,15,16,17,18,19,20] >>> fixList(a) [0, 1, 2, … Read more

[Solved] Deal with extremely large numbers with Python Programming [closed]

There’s nothing that makes recursion inherently more efficient. Moreover, the same algorithm implemented with recursion is likely to be less efficient due to function call overhead. Worse than that, and this is exactly your case, using recursions of large depth is likely to cause stack overflow (no pun intended). Unless tail-recursion optimization is in use, … Read more

[Solved] Add a new column with the list of values from all rows meeting a criterion

Something like this should work… df = pd.DataFrame({‘date’: [‘2017-01-01 01:01:01’, ‘2017-01-02 01:01:01’, ‘2017-01-03 01:01:01’, ‘2017-01-30 01:01:01’, ‘2017-01-31 01:01:01’], ‘value’: [99,98,97,95,94]}) df[‘date’] = pd.to_datetime(df[‘date’]) def get_list(row): subset = df[(row[‘date’] – df[‘date’] <= pd.to_timedelta(‘5 days’)) & (row[‘date’] – df[‘date’] >= pd.to_timedelta(‘0 days’))] return str(subset[‘value’].tolist()) df[‘list’] = df.apply(get_list, axis=1) Output: date value list 0 2017-01-01 01:01:01 99 [99] … Read more

[Solved] SyntaxError: invalid syntax Python issue

I do not fully understand what you wanted to achieve but i think is one of the following 2: 1.return a continuous range of value between minimum and maximum. In this case you can use range and do not pass Y as input param. def Z(minimum,maximum): Y = range(minimum, maximum) return Y print Z(2,4) 2.you … Read more

[Solved] There is an array array1=[20,10,4,3,8,9,30]. There result array should have the immediate next number of the main array. i.e array2=[30,20,8,4,9,30] [closed]

There is an array array1=[20,10,4,3,8,9,30]. There result array should have the immediate next number of the main array. i.e array2=[30,20,8,4,9,30] [closed] solved There is an array array1=[20,10,4,3,8,9,30]. There result array should have the immediate next number of the main array. i.e array2=[30,20,8,4,9,30] [closed]

[Solved] how to convert string consisted of list to real list [closed]

You can use ast.literal_eval to safely evaluate strings containing Python literals. from ast import literal_eval a=”[“Hello”, “World!”, 2]” b = literal_eval(a) # [“Hello”, “World!”, 2] Note that the string can only be compromised of: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None (taken from the documentation here) solved how to convert string consisted … Read more