Python permutations, variable survives recursion
I have a problem with my code. Variable "used" survives recursion (it doesn't return to before state, but stays the same). I understand this is common for default variable, however, "used" isn't default now, can somebody explain how does it happen?
newArray = []
def permutations(used, default=None):
if default is None:
default = used
used = []
if len(used) == len(default):
newArray.append(used)
return
else:
for i in range(len(default)):
if default[i] in used:
continue
used.append(default[i])
permutations(used, default)
print(permutations(['1', '2', '3']))
See also questions close to this topic

Want to Retrieve Xpath of Given WebElement using selenium / Python
How to retrieve XPath of an element using python  selenium. I know the class name for elements and there are multiple elements with same classnames.

How to covert lists of dict time series data to pandas series?
Suppose I have 1000 items timeseries dictionary data saved in the python list and some nontimeseries keys. The problems are that there are some different timeseries keys each list. Here are two examples of data items in the list.
[{'00:00:00': 1430801.0, '00:05:00': 1430806.0, '00:10:00': 1430811.0, '00:15:00': 1430815.0, '00:20:00': 1430821.0, 'dt': '20160718', 'a': 'Jack' 'b': 'Tony'}, {'00:10:00': 1430201.0, '00:25:00': 1430106.0, '00:40:00': 1430311.0, '00:55:00': 1430415.0, '01:10:00': 1430521.0, 'dt': '20160719', 'a': 'Jack' 'b': 'Tony'}]
I want to covert this list to pandas Series like following: Se[Jack_Tony]：
20160718 00:00:00: 1430801.0 20160718 00:05:00: 1430806.0 20160718 00:10:00: 1430811.0 20160718 00:15:00: 1430815.0 20160718 00:20:00: 1430821.0 20160719 00:10:00: 1430201.0 20160719 00:25:00: 1430106.0 20160719 00:40:00: 1430311.0 20160719 00:55:00: 1430415.0 20160719 01:10:00: 1430521.0

pandas groupby categories with some categories grouped together
The title of the question is very vague, but essentially, I want to run a
groupby
function on a pandas dataframe where I want to group by a column 'Category' with unique values of categories beingmilk
,dark
,caramel
andx
,y
,z
, etc. The column I want to perform aggregation on has the Quantity data for the number of chocolates of any kind sold. Now, I know that ifgroupby('Category').sum().plot.bar()
, I will see tall bars representing high volumes for themilk
anddark
category and really small (if any) bars for the other 4 categories. I would like to group the other categories together such that the final plot only has 3 bars e.g. formilk
,dark
andothers
. What is the easiest way to achieve this? Thanks! 
javarecursively finding a specific path in array
i would like to know to can i calculate 2 specific paths in a given array.
how can i return the shortest (or longest) path from [0][0] to [m][n]? i manage to progress through the array recursively but i don't know how i can "save" the paths and check which one is smaller to return.
 this one's a bit more specific and complicated each cell has an integer (pos/neg), and valid progressions in the array are n+1 or m+1. i would like to add each cell's value and return the lowest possible number that will guarantee a positive sum of all the cells from [0][0] to [n][m]. for example, if the lowest sum of path x is 3, the number returned will be 4 (43=1).
the 2nd request is a question i've been stuck at for quite a while but i've seen other questions regarding using and calculating stuff with the values in those arrays.

Recursive search for a file extension in ftp server
I need to find files with extension
.shp
, and then get his paths, in the subfolders of this ftp server ftp://geoftp.ibge.gov.br/ how could I do this through shell scripting? 
printing out every subdirectory without using recursion, instead using loops
My task is to print out every subdirectory without using a recursion. I have to use two functions, one will fill the array with every subdirectory and then print this array, the other is for resizing the array. I know this is a bad practice that I have to resize array every time I want to add something to it, but it is how I should do it. Also, I'm not allowed to use the function of getting the parent of a directory and SearchOption.AllDirectories. It has to be done using loops.
class Program { static void Main(string[] args) { string path = @"D:\Heaven Benchmark 4.0"; WriteDirectories(path); Console.ReadKey(); } static void WriteDirectories(string path) { string[] dirs = Directory.GetDirectories(path); string[] allDirs = new string[0]; for (int i = 0; i < allDirs.Length; i++) { Console.WriteLine(allDirs[i]); } } static void ResizeArray(ref string[] arr, int newSize) { string[] newArr = new string[newSize]; for (int i = 0; i < newSize  1; i++) { newArr[i] = arr[i]; } arr = newArr; } }
I'm thinking about filling array allDirs with every existing subdirectory of a path and then printing it out. is there any better and easier way of doing this?

Possibilities to construct 2^n height tower with 2x2 base of 2x1x1 blocks
How many possibilities exists to build a 2^n tower (with base area 2x2) of 2x1x1 Blocks? This has to be a divide and conquer algorithm, as I understood so far. I figured out the O(2^n), but I would like to solve this problem in polynomial time.
The main problem in my case is to figure out the "conquer" part.
Could somebody give me an advise how to solve this problem in polynomial time?

Ordered ranking for a list of permutations
I am trying to develop a method for finding the orderd rank of a particular sequence in the following lists.
a = list(sorted(itertools.combinations(range(0,5),3))) b = list(sorted(itertools.permutations(range(0,5),3)))
a
represents a list of elemnts of a combinatorial number system so the formula for rank is pretty straight forward.What I need are 2 function magic_rank_1 and magic_rank_2 which have the following definitions
def magic_rank_1(perm_item,permutation_list_object): ## permutation_list_object is actually b return list_object.index(perm_item) def magic_rank_2(perm_item,permutation_list_object,combination_list_object): ## permutation_list_object is actually b and combination_list_object is actually a return combination_list_object.index(tuple(sorted(perm_item)))
So basically
magic_rank_2((0,1,2),b,a) = magic_rank_2((2,0,1),b,a)
Sounds easy.. but i have a few restrictions.
 I cant use the indexof function because I cannot afford to search lists >100000000 items for every item
 I need magic_rank_1 and magic_rank_2 to be purely mathematical without using any sort function or comparison functions or search function. All the information I will have is the tuple whose rank needs to be identified and the last letter of my alphabet (in this case that will be 5)
 magic rank 2 need not be a number between 0 and k1 when k = len(a) as long as it is a unique number between 0 and 2^(ceiling((max_alphabet/2)+1))
I know magic_rank_1 can be calculated by something similar to this but there is a difference ,there every letter of the input alphabet is used, in my case it is a subset
Lastly yes this is supposed to be a substitute for a hashing function, currently using a hashing function but I am not taking advantage of the fact that
magic_rank_2((0,1,2),b,a) = magic_rank_2((2,0,1),b,a)
. If i can it will reduce my storage space requirements significantly as the length of my sequences is actually 5 , so if I can calculate a method for magic_rank_2 I reduce my storage requirement to 1% of current requirementUPDATE  For magic_rank_2 there should be no comparison operation between elements of the tuple, i.e no sorting, min,max etc
that only makes the algorithm less efficient than regular hashing

How to loop through a combination only once
I'm using vba in Excel and I wish to loop through sets of numbers, but I wish to loop through a combination only once. I'm currently looping through all permutations, which cause combinations to be repeated. For example:
For i = 1 to 4 'execute some code For k = 1 to 4 'execute some code Next Next
This will give the following combinations of i and j:
[1,1] dont want as 1 is repeated twice [1,2] yes please [1,3] yes please [1,4] yes please [2,1] dont want as [1,2] was already given, the order doesnt matter [2,2] dont want as 2 is repeated twice [2,3] yes please [2,4] yes please etc.
Catch my drift? The following post also deals with it, but it is unfortunately in Java and I can't make sense of the logic behind it to adapt it for vba in Excel: loop through combination once. I've simplified my explanation by using only two variables i and j, where in actual fact it is more combinations (up to 8 For loops) and they loop from about 100 to 900 which require extreme processing time to go through all permutations. Thus hoping to get some idea on how to go through only unique combinations, which will cut down the processing time significantly.
Any help will be much appreciated