prolog misunderstanding. Split list into two list with even and odd positions. where is my mistake?

I'm trying to split a list into two other list. List Even with the elemnts in even possition and a List Odd with the others. I've been looking over iinternet a solution, but all seem to me like chinese, i can not understand the process. So this is what i've been trying:

At this point, the list that you made at the beginning, [a|Z] is now [a|[b|Z]], which is [a,b|Z].

So, you create a list in the variable passed as the second argument, and stick H at the front of the list. The rest of the list you give to the recursive call. You will keep adding elements to the end of the list until the first list is the empty list. At that point, you will have end the new list, too:

foo([], []).

In your example, there is another predicate mutually recursive with the first one:

This matches your input/output examples, but I had to use descending numbers to get the example answers. Are you sure your explanation is correct? If not, just use 0123456789 instead of 9876543210 in the code below. The algorithm is to provide a sorting key based on translating the digits of...

You may have to define your own function.Here is an example I just tested, hope it is helpful to you(BTW: It is not advisable to implement such kind of functions in mysql. Maybe it is better to let the application servers to compute it instead of mysql :)). DELIMITER $$...

I think you want something more like: print("Enter positive, negative or zero to determine the average: ") # get list of values/numbers from the user values = [i for i in iter(lambda: int(input("Enter a number (-9999 to end): ")), -9999)] -9999 is the sentinel value to break the loop def...

I can try to explain what is going on. You are trying to find the longest substring in alphabetical order by looking for the end of the substring. Your definition of end is that there is a character less than the last character in the string -- something in descending...

I want to put all the lines of the file in a list Then you are working currently working too hard. You can use File.ReadLines, which yields an IEnumerable<string> and pass that into a List<string>: var allTextLines = new List<string>(File.ReadLines(path)); ...

Since, request.GET is a dictionary, you can access its values like this: for var in request.GET: value = request.GET[var] # do something with the value ... Or if you want to put the values in a list: val_list = [] for var in request.GET: var_list.append(request.GET[var]) ...

Could not figure out a regex solution, but here's a non-regex solution. It involves parsing numbers (not in curly braces) before each comma (unless its the last number in the string) and parsing strings (in curly braces) until the closing curly brace of the group is found. If regex solution...

You can use a list comprehension to do both splits at once and return a list of lists: >>> a = '{1;5}{2;7}{3;9}{4;8}' >>> [item.split(';') for item in a[1:-1].split('}{')] [['1', '5'], ['2', '7'], ['3', '9'], ['4', '8']] ...

You are not using curly braces, so you cannot see where the object is disposed. You code is identical to this code: List<StreamReader> lijst = new List<StreamReader>(); using (StreamReader qwe = new StreamReader("C:\\123.txt")) { using (StreamReader qwer = new StreamReader("C:\\1234.txt")) { lijst.Add(qwe); } } lijst.Add(qwer); This means that when you...

Based on your code where you're filling your 4D list: List<string> Lijst1D = new List<string>(); Lijst2D.Add(Lijst1D); Here you're creating new List<string> and adding it to parent 2D list. But Lijst1D itself doesn't contains any elements (you haven't added anything to it), so Lijst4D[0] will throw that IndexOutOfRangeException as well as...

I believe you are incorrectly referencing to num instead of line which is the counter variable in your for loops, you either need to use num as the counter variable, or use line in the if condition. def countGasGuzzlers(list1, list2): total = 0 CCount = 0 HCount = 0 for...

You can simply filter the tuples from the list as a generator expression and then you can stop taking the values from the generator expression when you get the first tuple whose second element is -1, like this >>> s = [(0,-1), (1,0), (2,-1), (3,0), (4,0), (5,-1), (6,0), (7,-1)] >>>...

Removing with listOfInstances.get(1).getArrayList().remove(1); is enough and valid. In order to demonstrate this, I've written a test code for you. I've just removed the second object's ArrayList's second String element, you can compare the initial and updated states; import java.util.ArrayList; import java.util.Arrays; public class TestQuestion { public static void main(String[] args)...

The problem is you are trying to insert as the first element of the list, list5 which is incorrect. You have to access the first element of the list and insert it to that list. This can be done using the following code >>> list5 = [[], [(1,2,3,4), 2, 5]]...

Append isn't supposed to modify anything Why doesn't append affect list y? The first sentence of the documentation on append is (emphasis added): append returns a new list that is the concatenation of the copies. No one ever said that append is supposed to modify a list. You can't change...

From this comment: @user2357112 her is initialization of deck of card (its source for random_itemst_stac): self.__talia = 8 * [Card(j) for j in range(1,14)] This means that you have multiple references to the same cards in your random_itemst_stac. You should be making a new Card for each card you need...

You could just check the nesting level by counting parents $("ul li").each(function() { if ( $(this).parents('ul').length < 3 ) { // do stuff } }); FIDDLE To make it more dynamic one could simply find the deepest nesting level and filter based on that var lis = $("ul li"); var...

This is quick and dirty, but find-dup should return the first duplicated item (in this case a sublist) in the list. to go let listA [[-9 2] [-9 1] [-9 0][-9 -1][-9 -2][-9 -3][-9 -4][-8 0][-9 0]] show find-dup listA end to-report find-dup [ c ] ;returns the first duplicated...

pure for zip lists repeats the value forever, so it's not possible to define a zippy applicative instance for Scala's List (or for anything like lists). Scalaz does provide a Zip tag for Stream and the appropriate zippy applicative instance, but as far as I know it's still pretty broken....

You're reading the wrong documentation: you should read ListIterator's javadoc. It says: Throws: ... IllegalStateException - if neither next nor previous have been called, or remove or add have been called after the last call to next or previous Now, if you want a reason, it's rather simple. You're playing...

Your list is for all intents and purposes a base-100 number. The easy way to solve it is to do the arithmetic in the same way in which you would evaluate it long hand: start with the least significant digit, working to the most significant digit, sum each pair of...

Python does not support boolean indexing but you can use the itertools.compress function. In [49]: from itertools import compress In [50]: l = ['a','b','c'] In [51]: b = [True,False,False] In [52]: list(compress(l,b)) Out[52]: ['a'] ...

First you have unnecessary escaping inside your character class. Your regex is same as: String pattern = "[(?=)]"; Now, you are getting an empty result because ( is the very first character in the string and split at 0th position will indeed cause an empty string. To avoid that result...

With such a small range you could just iterate the move_order and check if each element exists in the allowed moves def start(): move_order=[c for c in raw_input("Enter your moves: ")] moves = ['A','D','S','C','H'] for c in move_order: if c not in moves: print "That's not a proper move!" return...

Your list contains one dictionary you can access the data inside like this : >>> yourlist[0]["popularity"] 2354 [0] for the first item in the list (the dictionary). ["popularity"] to get the value associated to the key 'popularity' in the dictionary....

If you want the None and '' values to appear last, you can have your key function return a tuple, so the list is sorted by the natural order of that tuple. The tuple has the form (is_none, is_empty, value); this way, the tuple for a None value will be...

According to documentation of numpy.reshape , it returns a new array object with the new shape specified by the parameters (given that, with the new shape, the amount of elements in the array remain unchanged) , without changing the shape of the original object, so when you are calling the...

It's a bug. Fixed in 0.15.0 You're passing in empty arrays, and the function handles it incorrectly. Either update your Scipy, or skip if the arrays are empty (though check that your data isn't wrong and that it makes sense to have an empty array there). Some suggestions for your...

Change your last line to: nodeclass[k].extend(nodeindex) The two extra list wrappings you're creating are happening in: The list comprehension inside the indices function. The [nodeindex] wrap in the append call. ...