convert generator object to list [closed] - list

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Trying to convert this generator into a list of list. Got an error: TypeError: 'tuple' object is not callable. Using python 2.7
perm = itertools.permutations(range(1, 4))

If the goal is to convert to a list of lists (instead of generator of tuples), map can do this easily:
perms = map(list, itertools.permutations(range(1,4)))
If a list of tuples is all you need, it's even easier:
perms = list(itertools.permutations(range(1,4)))
Just don't do it for permutations on a larger set of inputs, or you'll exhaust memory pretty quickly.

Related

How to use regex to pull out a specific value in classic asp [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I can't figure out a way to pull out two numbers in a string and save them in a different variable in classic asp.
The string is:
"\1800_411.pdf.log"
All I was trying to do is to save the first number which is 1800 in a variable and save the 411 in a different variable
What about:
(\d+)_(\d+)
This would save them into two capturing groups. See here: https://regex101.com/r/v83Zbt/1

For loop fails, but code appears to be correct [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
My code looks fine to me, but I'm getting a syntax error in my for loop. Does anyone know why this would be the case? I've included my code below:
def printLine(numberOfDots):
dots = 0
for x in range numberOfDots:
dots += 1
printDots = print("." * dots)
return printDots
printLine(20)
range is a function, so you should use range(numberOfDots) instead of range numberOfDots.

How to get more than 50 transitions in boost msm? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am using boost msm to implement HSM and I am at the point where the maximum number of transitions possible is 50. I looked at some blog posts and they said that if we create /mpl/vector/vector60.hpp, it should work. I tried and this is the error I get
I am wondering how I am generate these vector60, vector70.hpp .. files or map60, map70.hpp files so that I can get more transitions.

Is it correct to fill sets contained in vector? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a vector<set<int>> v(10);. Each set can be filled by some data. Then I insert integers to randomly sets, e.g. v[5].insert(99);. Can it cause undefined behavior?
Only if you go out of bounds of the vector.
If your vector has at least 6 elements, then v[5].insert(99); is well defined.
To be sure that you don't, you can use the at accessor function:
v.at(5).insert(99);
Which will throw a std::out_of_range exception if you try to access past the end of the array.

List of lists in scala changing particular elements [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am given a list of list made of integers. I have to override the toString method to print this list of lists in a particular format.
However, I also need to change every '1' element that is in the list into an 'a.
Remember your list is a list of lists, so you need something like:
list.map(_.map { case 1 => "a"; case x => x})
I think you cannot override a method for the Int class, but you create your own class which inherits from Int and use instances of that class instead.
Here is a way to make your code work. I used x.toString because this returns a List[List[String]]. If you omit it, you'll get a List[List[Any]] which contains strings and integers, rather than all strings.
list.map(_.map { case 1 => "a"; case x => x.toString } )