[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] Generics C# organization of methods that depends on type [closed]

Introduction Solution The reason you’re getting the compiler error is that you’ve pushed the generic constrains to the individual methods rather than putting the restraint on the class. The way you have it, there’s no way to override the intrinsically generic method GetOrderingFunc<T> with a method that returns a Expression<Func<User, string>>. What you’ve posted works … Read more

[Solved] Database – SQL Table to Perl Script

Introduction Solution If you add use strict and use warnings you’ll probably get some feedback about needing to declare @tran in the code below: while(my @row = $tran->fetchrow_hash) { my $tran = join ‘,’, @row; $trans{$tran[2]}{$tran[3]} += $tran[4]; } $tran is 657520,02-07-1999,016901581432,Debit,16000 when you try and use it as an array. Use Data::Dumper to show … Read more

[Solved] Comment xml elements programmatically

Introduction Solution You can do it easily with XDocument var xDocument = XDocument.Parse(@”<configuration> <property> <name>name</name> <value>dinesh</value> </property> <property> <name>city</name> <value>Delhi</value> </property> </configuration>”); var firstPropertyElement = xDocument .Descendants(“property”) .First();//Find your element var xComment = new XComment(firstPropertyElement.ToString());//Create comment firstPropertyElement.ReplaceWith(xComment);//Replace the element with comment Console.WriteLine(xDocument); Which outputs: <configuration> <!–<property> <name>name</name> <value>dinesh</value> </property>–> <property> <name>city</name> <value>Delhi</value> </property> </configuration>