[Solved] Making new list of lists from elements of some other lists

A pythonic implementation. [i.append(Origin[0][0]) for i in Points] print [[item1[0],item1[-1],item2] for item1,item2 in zip(Points,Distance)] Result [[‘A’, ‘J’, 0.28], [‘B’, ‘J’, 0.23], [‘C’, ‘J’, 0.3], [‘D’, ‘J’, 0.22], [‘E’, ‘J’, 0.75], [‘F’, ‘J’, 0.37], [‘G’, ‘J’, 0.17], [‘H’, ‘J’, 0.09], [‘I’, ‘J’, 0.13], [‘J’, ‘J’, 0.0]] solved Making new list of lists from elements of some … Read more

[Solved] How to correctly initialize a list member object in Java

The first constructor: public Book(String bookname, String authorName) { mBookName = bookname; mAuthorName = authorName; mPageList = new ArrayList<>(); } Then you will have a new book without any page The second constructor: public Book(String bookname, String authorName, List<Page> pageList) { mBookName = bookname; mAuthorName = authorName; mPageList = pageList; } You will have a … Read more

[Solved] extracting specific format elements from the list in c#

var abc = new List<string> { “abc”, “123”, “abd12” }; var alphaXorNumerical = abc.Where(str => str.All(Char.IsDigit) || str.All(Char.IsLetter)); var others = abc.Except(alphaXorNumerical); If you also want to check for whitespace, use this instead: var alphaXorNumerical = abc .Where(str => str.All(Char.IsDigit) || str.All(ch => Char.IsLetter(ch) || Char.IsWhiteSpace(ch))); 11 solved extracting specific format elements from the list … Read more

[Solved] Count occurences of all items of a list in a tuple

Being NumPy tagged, here’s a NumPy solution – In [846]: import numpy as np In [847]: t = (1,5,2,3,4,5,6,7,3,2,2,4,3) In [848]: a = [1,2,3] In [849]: np.in1d(t,a).sum() Out[849]: 7 # Alternatively with np.count_nonzero for summing booleans In [850]: np.count_nonzero(np.in1d(t,a)) Out[850]: 7 Another NumPy one with np.bincount for the specific case of positive numbered elements in … Read more

[Solved] python list permutations [duplicate]

itertools.permutations does this for you. Otherwise, a simple method consist in finding the permutations recursively: you successively select the first element of the output, then ask your function to find all the permutations of the remaining elements. A slightly different, but similar solution can be found at https://stackoverflow.com/a/104436/42973. It finds all the permutations of the … Read more

[Solved] How to get number of occurences of items after certain item in list

Try this one-liner: reduce(lambda acc, cur: acc + ([] if cur[1] == ‘you’ else [next((i[0] – cur[0] – 1 for i in list(enumerate(my_list))[cur[0]+1:] if i[1] == ‘hello’), len(my_list) – cur[0] – 1)]), enumerate(my_list), []) It will give an array where the nth element is the number of ‘you’s following the nth occurrence of ‘hello’. e.g. … Read more

[Solved] Java remove dupplicate attribute in List

static class Message { String message; long time; public Message(String message, long time) { this.message = message; this.time = time; } } public static void putLatestMessage(Map<String, Message> messageMap, Message message) { if (messageMap.containsKey(message.message) && messageMap.get(message.message).time >= message.time) { return; } else { messageMap.put(message.message, message); } } public static void main(String[] args) { Map<String, Message> messageMap … Read more

[Solved] Python Linked list minimum value

Answering this specifically would be difficult without knowing the specifics of your node implementation, and as this is almost certainly a homework problem wouldn’t be sporting anyway. What you want to do is go through each element of the list, and compare it to the Min you have. If it’s higher, then just go to … Read more