[Solved] Check to see if two lists have the same value at the same index, if so return the index. If not return -1

Introduction Solution I think a cleaner answer uses the built-in enumerate and zip functions: Dlist = [17,13,10,6,2] Ilist = [5,9,10,15,18] def seqsearch(DS,IS): for idx, (d, s) in enumerate(zip(DS, IS)): if d == s: return f”Yes! Found at index = {idx}” return “No!\n-1” print(seqsearch(Dlist,Ilist)) It’s unclear whether you want to return just the first index, or … Read more

[Solved] Need Someone That Can Read This VBA Script! Fairly Simple [closed]

Public Sub MakeColumnsFromRows() Dim totalCutsToMake As Integer Dim currentColumn As Integer Dim currentCut As Integer Dim rowsToCut As Integer Sheets(4).Activate rowsToSkip = 10 totalCutsToMake = (ActiveSheet.UsedRange.Rows.Count / rowsToSkip) currentColumn = 1 Dim RowCount As Integer For currentCut = 1 To totalCutsToMake RowCount = Cells(Rows.Count, currentColumn).End(xlUp).Row Range(Cells(rowsToSkip + 1, currentColumn), Cells(RowCount, currentColumn + 2)).Select Selection.Cut Cells(1, … Read more

[Solved] Unit Testing with ForEach [closed]

There is probably a lot you could do, but the first thing to do would be to make it more readable. Perhaps something like this: var nullActivities = from p in partnerList from t in p.Tenants let activity = agent.GetShopActivity(t, startDate, endDate) where activity == null select activity; Assert.Empty(nullActivities); Moreover: you may want to think … Read more

[Solved] You are given an array consisting of n integers. Print the last two digits of the product of its array values [duplicate]

You can try this (it’s version of Python3): n = int(input()) arr = list(map(int, input().rstrip().split())) result = 1 for num in arr: result = (result * num) % 100 print(“{:02d}”.format(result)) A little bit modify for better algorithm: n = int(input()) arr = list(map(int, input().rstrip().split())) result = 1 for num in arr: result = (result * … Read more

[Solved] Python List of Dictionaries by Loops

If you want only print the resulting dictionaries, uncomment the print statement (and comment the following 2). d1 = [ {‘index’:’1′,’color’:’red’}, {‘index’:’2′,’color’:’blue’}, {‘index’:’3′,’color’:’green’} ] d2 = [ {‘device’:’1′,’name’:’x’}, {‘device’:’2′,’name’:’y’}, {‘device’:’3′,’name’:’z’} ] result_list = [] for dict1 in d1: merged_dict = dict1.copy() for dict2 in d2: merged_dict.update(dict2) # print(merged_dict) result_list.append(merged_dict.copy()) print(result_list) The result: [{‘name’: ‘x’, ‘device’: … Read more

[Solved] Remove duplicates from a Java List [duplicate]

There are two possbile solutions. The first one is to override the equals method. Simply add: public class DataRecord { […..] private String TUN; @Override public boolean equals(Object o) { if (o instanceof DataRecord) { DataRecord that = (DataRecord) o; return Objects.equals(this.TUN, that.TUN); } return false; } @Override public int hashCode() { return Objects.hashCode(TUN); } … Read more