[Solved] Two list count specific elements and aggregate on spefic rule [closed]

There are many possible solutions. In my opininion this is the easiest: import heapq list1 = [2,5,7] list2=[4,6,9] counter1=0 counter2=0 sum1=0 sum2=0 full_list = list1 + list2 three_largest = heapq.nlargest(3,full_list) for n in three_largest: if n in list1: list1.remove(n) counter1+=1 sum1+=n else: list2.remove(n) counter2+=1 sum2+=n print(counter1) print(counter2) print(sum1) print(sum2) Note that you made a mistake … Read more

[Solved] Show Date as dddd Mmmm d, yyyy SQL

Use the following with DateName and convert functions : select DateName( month , q.dt )+’ ‘+convert(char,day(q.dt))+’, ‘+convert(char,year(q.dt)) from ( select convert(date,’20180802′) as dt ) q; SQL Fiddle Demo With respect to your last comment make your query as : select DateName( weekday , q.dt )+’ ‘+ DateName( month , q.dt )+’ ‘+ convert(char,day(q.dt))+’, ‘+convert(char,year(q.dt)) as … Read more

[Solved] Create python dictionary from TXT file – value aggregation

No need to bother with pandas. Text files are iterable. Just open it, operate on the line (string) and fill a dictionnary. file = “font.txt” with open(file, “r”) as f: dic = dict() for line in f: x = line.strip(“\n”).split(” “) key = int(x[0].strip(“px”)) value = int(x[1]) if key not in dic.keys(): dic[key] = [value] … Read more

[Solved] Reduce array of objects to x number of items. Trying to keep at least 2 of specific object property value

So here’s my attempt at solving your issue/request, explanations in the code. let totalCount = array.length; let typeCounts = {}; // Separate the array by type and move to an object for easier access // Result: { product: [{id:0,type:’product’,name:’Product 1′},{id:0,type:’product’,name:’Product 2′},{id:0,type:’product’,name:’Product 3′}], accessory: [ … ], … } array.map((elem) => typeCounts[elem.type] = […(typeCounts[elem.type] ? typeCounts[elem.type] … Read more

[Solved] I Want a Search Box With a Button Where I Can Copy Any Of The Image URL And I Want That Image To Be Displayed On The Same Web Page

<!DOCTYPE html> <html> <body> <input type=”search” id=”linkit”> <button onclick=”searchPic()”>Search Image</button> <div> <img id=”myImage” src=”” style=”width:100px”> </div> <script> function searchPic() { searchValue= document.getElementById(‘linkit’).value; alert(searchValue); document.getElementById(‘myImage’).src = searchValue; } </script> </body> </html> copy and paste any Image Url given below or any valid image url for testing https://placeimg.com/640/480/any http://via.placeholder.com/350×150 1 solved I Want a Search Box With … Read more

[Solved] Strange JQuery behavior

After spending hours I finally found the reason : 1: In VS2015 code works as expected 2: In VS2017 statement if (1>5) gets resolved to true!!! (Pay attention to space after if 3: in VS2017 statement if(1>5) works as Expected! Now I’m convinced this is VS2017 bug. Reference: mozilla.org A whitespace character is an empty … Read more

[Solved] To print sum of numbers from this string

you can use this to separate text and number first then proceed further, preg_match_all(‘/[^\d]+/’, $string, $textMatch); preg_match(‘/\d+/’, $string, $numMatch); $text = $textMatch[0]; $num = $numMatch[0]; 2 solved To print sum of numbers from this string