list

python using set to create list of elements that only appear once [duplicate]

廉价感情. 提交于 2021-02-11 12:50:34
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How can I make my code be a set? python takes list and returns only if negative value also exists using set Basically I have a huge list: # with (n) being a number in the hundreds of thousands or millions def big_list(n): return [ randrange(n) for i in range(n) ] What I need to do is create a new list containing only the elements of big_list(n) that appear once using set . I'm really stuck so anything that could

How to update values dynamically for the individual match sections within sshd config file using puppet

旧巷老猫 提交于 2021-02-11 12:48:55
问题 i am able to update the value to the sections "User foo" and "Host *.example.net" by passing the index. If i pass index 1 or 2 the respective value is getting updated. my code: $sections = ['Host *.example.net', 'User foo'] $sections.each |String $section| { sshd_config_match { "${section}": ensure => present, } } $settings = [['User foo', 'X11Forwarding yes', 'banner none'],['Host *.example.net', 'X11Forwarding no', 'banner none']] $settings.each |Array $setting| { $setting_array = split(

Convert complex term to List of lists and then back to term with modified functor

落花浮王杯 提交于 2021-02-11 12:28:50
问题 you can use =.. to convert simple terms. ?- x(a,b,c) =.. A. A = [x, a, b, c]. what about complex terms : x(a,b(c,d)) ==> [x,a,[b,c,d]] x(a,b(c,q(d))) ==> [x,a,[b,c,[q,d]]] then as separate task i want to re-generate the terms with changed functor : x(a,b(c,d)) ==> [x,a,[b,c,d]] ==> y(a,f(c,d)) 回答1: deep_univ(X, Y) :- X =.. [H|Rest], ( Rest = [] -> Y = X ; maplist(deep_univ, Rest, ExpRest), Y=[H|ExpRest] ). rev_univ([H|Rest], Y) :- maplist(rev_univ, Rest, RestT), Y =.. [H|RestT]. rev_univ(H, H

Convert complex term to List of lists and then back to term with modified functor

不羁岁月 提交于 2021-02-11 12:27:35
问题 you can use =.. to convert simple terms. ?- x(a,b,c) =.. A. A = [x, a, b, c]. what about complex terms : x(a,b(c,d)) ==> [x,a,[b,c,d]] x(a,b(c,q(d))) ==> [x,a,[b,c,[q,d]]] then as separate task i want to re-generate the terms with changed functor : x(a,b(c,d)) ==> [x,a,[b,c,d]] ==> y(a,f(c,d)) 回答1: deep_univ(X, Y) :- X =.. [H|Rest], ( Rest = [] -> Y = X ; maplist(deep_univ, Rest, ExpRest), Y=[H|ExpRest] ). rev_univ([H|Rest], Y) :- maplist(rev_univ, Rest, RestT), Y =.. [H|RestT]. rev_univ(H, H

How do i make a sublist of every CSV row and put that sublist inside a list

被刻印的时光 ゝ 提交于 2021-02-11 12:22:28
问题 I'm making a sublist of every row inside a csv file but i'm getting a single list back wines_list = [] for row in wines: wines_list.append(row) print(wines_list) This returns: ['id', 'country', 'description', 'designation', 'points', 'price', 'province', 'taster_name', 'title', 'variety', 'winery', 'fixed acidity', 'volatile acidity', 'citric acid', 'residual sugar', 'chlorides', 'free sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates', 'alcohol'] But i wan't it to append

Get a list of objects with the maximum attribute value in a list of objects

依然范特西╮ 提交于 2021-02-11 09:52:12
问题 Slightly different from previous questions. I have found here: front_Ar is a list of objects with a score attribute. I am trying to get a list of all objects with the highest score. I have tried: maxind = [] maxInd.append(max(front_Ar, key=attrgetter('score'))) which stored only one object (presumably the first one it found). Any idea how can this be done? 回答1: Find the max score first, then filter the list based on that score: max_score = max(front_Ar, key=attrgetter('score')).score max_ind

How to select a chunk of list between two values in python

爱⌒轻易说出口 提交于 2021-02-11 08:14:33
问题 I have a list of values like this: vect_i = ['a','X','c','g','X','t','o','X','q','w','e','r','t','y','u','i','o','p','Y','x','c','v','b','Y','b','n','m','Y','q','a','d','Y',] my goal would be to select in a smart way only the values that are within the last X and the first Y (notice capital X and Y). The output should be something like this: vect_f = ['q','w','e','r','t','y','u','i','o','p','Y','x','c','v','b'] Is there a smart way to do this selection. I have figured out a way to do it by

Error when trying to store list in data.table of length 1

和自甴很熟 提交于 2021-02-11 08:13:40
问题 When trying to store a vector in a data.table, this works only when the data.table has length of more than one. Please find below a simplified version of the problem library(data.table) Working fine dt <- data.table( a = c("a", "b"), l = list()) dt$l[[1]] <- c(1:3) Results in: a l 1: a 1,2,3 2: b Producing Error dt <- data.table( a = c("a"), l = list()) dt$l[[1]] <- c(1:3) Error in [<-.data.table(x, j = name, value = value) : Supplied 3 items to be assigned to 1 items of column 'l'. The RHS

How to test for equality of Lists of String arrays

江枫思渺然 提交于 2021-02-11 08:10:37
问题 I think I can't see the forest for the trees... How do I test for equality (not identity) of all elements recursively in a List of String arrays? Here's a minimal example: List<String[]> left = new ArrayList<>(); left.add(new String[]{"one", "two"}); List<String[]> right = new ArrayList<>(); right.add(new String[]{"one", "two"}); System.out.println(left.equals(right) ? "Yeah!" : "This is not what I want."); I want to use this in unit tests. A bit more context: I have a class that holds

print list<object> in console c# [duplicate]

橙三吉。 提交于 2021-02-11 07:47:29
问题 This question already has answers here : Print out object elements from list (2 answers) Print List of objects to Console (3 answers) Closed last month . when i try to print a list of objects in c# it does not print what i want, let me demonstrate. example: public class Classname { public string hello; public string world; } namespace inloggning { class Program { static void Main(string[] args) { List<object> listOfObjects = new List<object>(); Classname example = new Classname(); example