spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » LIST » Page 1
Prolog - New list with positive, negative and "0" elements with 1, -1, 0 respectively in relation to input list
you can simplify a lot your code replace([], []). replace([O|T], [R|T2]) :- convert(O,R), replace(T, T2). convert(N,1) :- N > 0. convert(N,0) :- N =:= 0. convert(N,-1) :- N < 0. when you have convert/2, you can do ?- maplist(convert, In, Out). and forget about replace/2

Categories : List

unix - how to get (2) columns from each dictionary, from a list of dictionaries
sed 's/ {/ /g' yourJsonFile | cut -d, -f4,6 @shelter found the answer, I do't know why he deleted it. It just missed the space before the { character to avoid sed to put a in the first ocurrence of { creating a line consisting by just a [. Example $ cat yourJsonFile [{"prescSpecialty": "10201", "threeDigitSubsZip": "852", "untsDispensedQuantity": "60.000", "generic": "Y", "gender": "F", "n

Categories : List

List being shortened when writing it to a txt file
As you discovered, the file is not being closed because you left the parentheses off: should be f.close() instead of f.close. But I thought I would also post an answer that shows how you might do this in a bit more idiomatic Python, where the call to f.close() is done for you, even if an error occurs in your loop: timlist = [1,2,3,4] acclist = [9,8,7,6] with open('file.txt', 'w') as f: # use a c

Categories : List

Prolog: Split list at integer in list of lists
You have an issue with take1word/3: it will take a word if there is an integer in the list, but it will not take the last word. You need to add another base clause to it: take1word([], [], []). take1word([H|T],[],T) :- integer(H). take1word([H|T],[H|Hs],Y) :- float(H), take1word(T,Hs,Y); atom(H), take1word(T,Hs,Y). Now your separatewords/2 will work: separatewords([],[]). separatewords(L, [W|T

Categories : List

Haskell - Parallel list to tuples
Your definition is quite close to this way of defining parMap: parMap :: (a -> b) -> [a] -> Eval [b] parMap f [] = return [] parMap f (a:as) = do b <- rpar (f a) bs <- parMap f as return (b:bs) To use it, call runEval on the resulting Eval monad, e.g.: main = do list <- getWords "test.txt" let pairs = runEval $ parMap (x -> (x,1)) list ... Up

Categories : List

Scala: Type mismatch when using left fold
This is a very common error when using Nil. Nil extends List[Nothing] so you need to help the compiler a little bit to properly infer the actual type of B: def reverse[A] (list: List[A]) = { foldLeft(list,Nil:List[A])(Cons(_,_)) }

Categories : List

Depth first search Open and Closed list
Open list helps you in both depth first and breadth first searches to traverse your tree properly. Think about algorithms step by step. You are in a node with many children and your are going to expand one of them. After expansion there should be a mechanism to get back and continue your traversal. Open list performs that for you and tells you what is actually the next node to be expand. And the a

Categories : List

In Scheme how do I return only string from a list containing combination of string and numbers
(define (take-while p l) (let loop ((o '()) (l l)) (if (and (not (null? l)) (p (car l))) (loop (cons (car l) o) (cdr l)) (reverse o)))) (define (up-to-first-digit l) (take-while (lambda (x) (not (number? x))) l)) (up-to-first-digit '(q w c 9 5 6)) ;=> (q w c)

Categories : List

Which itemprop, itemscope and itemtype will be used for tenders in schema.org?
There are no specific item type for tendors so i beleive article type will best fit for that. itemtype="http://schema.org/Article" itemprop="name" - for heading or title itemprop="articleBody" - for content. You can use other itemtype as nested if there are person, business information in content of page.

Categories : List

Python3: list index out of range
numcards = (len(topDeck)) + (len(bottomDeck)) for g in range(numcards): newDeck.append(bottomDeck[g]) Your g goes up to the sum of lengths of topDeck and bottomDeck, hence becomes greater than len(bottomDeck).

Categories : List

count successive occurrences of number in Prolog
Why you are stating a relation between two lists with a predicate having 4 arguments ? Let's try to proceed step by step. An empty list gives an empty list, an element counted gets incremented, otherwise, start counting... count([],[]). count([X|T],[[X,C1]|R]) :- count(T,[[X,C]|R]), !, C1 is C+1. count([X|T],[[X,1]|R]) :- count(T,R). ?- count([1,1,1,2,2,2,3,1,1],R). R = [[1, 3], [2, 3], [3, 1],

Categories : List

In Scheme, how to compare two arguments and return false if one isn't given
Try this: (define (longer-list list1 list2) ; use `or` to check if either condition is true (if (or (not (list? list1)) (not (list? list2))) false <do something else here>)) Explanation: just check both arguments to see if either one is not a list and return false if that's the case. Otherwise, just do whatever you want to do in the "else" part of the conditional expressio

Categories : List

Common Lisp - Collect 'firsts' from nested lists of lists
How about something like this? (defun immediate-children (object &aux (result '())) (labels ((f (object) (cond ((consp object) (push (list* (first object) (mapcar #'f (rest object))) result) (first object)) (t object)))) (f object) result)) CL-USER> (

Categories : List

Adding items to a Google Forms list from a spreadsheet range
Nothing is pushed to your array FleetList. Also the coding in your loop is faulty. Assuming you want to push the first column (not including the header), try this and see if it works function GetFleet() { var values = SpreadsheetApp.getActiveSpreadsheet() .getSheets()[0].getDataRange() .getValues(); var FleetList = []; //Use column 0 and ignore row 1 (headers) for (var i = 1, len = val

Categories : List

Prolog - 'Member Of' List
First, Prolog doesn't have functions: it has predicates. Second, A non-empty prolog list is written using square brackets — [a,b,c,d] with the empty list denoted by the atom []. Lists are actually represented by the structure ./2, where the first argument is the first item (the head) of the list and the second argument is the remainder of the list, either another non-empty list, or the empt

Categories : List


Recently Add
Merging Two Lists in Racket R5RS
Prolog - New list with positive, negative and "0" elements with 1, -1, 0 respectively in relation to input list
unix - how to get (2) columns from each dictionary, from a list of dictionaries
List being shortened when writing it to a txt file
Prolog: Split list at integer in list of lists
Haskell - Parallel list to tuples
Scala: Type mismatch when using left fold
Depth first search Open and Closed list
In Scheme how do I return only string from a list containing combination of string and numbers
Which itemprop, itemscope and itemtype will be used for tenders in schema.org?
Python3: list index out of range
count successive occurrences of number in Prolog
In Scheme, how to compare two arguments and return false if one isn't given
Common Lisp - Collect 'firsts' from nested lists of lists
Adding items to a Google Forms list from a spreadsheet range
Prolog - 'Member Of' List
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.