2
votes
Fortnightly Programming Q&A Thread
General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.
Don't forget to format your code using the triple backticks or tildes:
Here is my schema:
```sql
CREATE TABLE article_to_warehouse (
article_id INTEGER
, warehouse_id INTEGER
)
;
```
How do I add a `UNIQUE` constraint?
I've got an algorithm that's in exponential time (ugh) and I can't seem to find a clever way around that. I've got a few optimizations that should let me abort early if there are bad combinations, but that's a separate issue. Anyone know a way to write for-loop chain that's depth is dependent on imported data in python?
I'm trying to avoid having to write nasty code like:
Especially since I don't know exactly how many members the for loop chain will have.
Thanks in advance!
EDIT:
The more I'm thinking about it, it should be trivial to calculate if I can generate every base-k number (where k is the number of options) of length n (where n is the length of my input). I think I can then write a function that takes that number as input, converts the numbers into the different choices and checks for optimizations and then runs
my_function
I guess my first question is, for the values that you are iterating over in each loop, are they constant as in your example?
If so, it seems like your innermost
my_function
could just be called on the product of[[1,2,3]] * depth
(wheredepth
is 24 in the case of aaa ... zzz). You could write this usingitertools.product
like so:Edit:
If you want to avoid allocating the
list
for the intermediateargs_list
, try consuming the generated args fromproduct
directly:That will do the trick. I'd totally forgotten that itertools existed. Thanks for your help!