logo
down
shadow

C# Linq Find all indexes of item in List<int> within another List<int>


C# Linq Find all indexes of item in List<int> within another List<int>

Content Index :

C# Linq Find all indexes of item in List<int> within another List<int>
Tag : chash , By : Jason Haar
Date : November 23 2020, 03:01 PM

fixed the issue. Will look into that further I have a List looks like:
var ResultList = List1.Select(x => List2.IndexOf(x));

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Find the position of a List Item in a List based upon specifice criteria using LINQ


Tag : chash , By : chawei
Date : March 29 2020, 07:55 AM
this one helps. Something similar to linq find in which position is my object in List, except his accepted answer is evaluating at an object level. , You could use something like:
public static IEnumerable<int> GetIndices<T>(this IEnumerable<T> items, Func<T, bool> predicate)
{
    return items.Select( (item, index) => new { Item = item, Index = index })
                     .Where(p => predicate(p.Item))
                     .Select(p => p.Index);
}

Find all the indexes of an item within a list using stream API


Tag : java , By : Alex Sadzawka
Date : March 29 2020, 07:55 AM
hop of those help? For a start, using Lambdas is not the solution to all problems... but, even then, as a for loop, you would write it:
List<Integer> results = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
    if (search == list.get(i).intValue()) {
        // found value at index i
        results.add(i);
    }
}
List<Integer> list = Arrays.asList(10, 6, 16, 46, 5, 16, 7);
int search = 16;
int[] indices = IntStream.range(0, list.size())
                .filter(i -> list.get(i) == search)
                .toArray();
System.out.printf("Found %d at indices %s%n", search, Arrays.toString(indices));
Found 16 at indices [2, 5]

Python Fastest way to find Indexes of item in list


Tag : python , By : Guyou
Date : March 29 2020, 07:55 AM
it fixes the issue If one was to attempt to find the indexes of an item in a list you could do it a couple different ways here is what I know to be the fastest
    def find(target, myList):
        for i in range(len(myList)):
            if myList[i] == target:
                yield i

    def find_with_list(myList, target):
         inds = []
         for i in range(len(myList)):
             if myList[i] == target:
                 inds += i,
         return inds


In [8]: x = range(50)*200
In [9]: %timeit [i for i,j in enumerate(x) if j == 3]
1000 loops, best of 3: 598 us per loop

In [10]: %timeit list(find(3,x))
1000 loops, best of 3: 607 us per loop
In [11]: %timeit find(3,x)
1000000 loops, best of 3: 375 ns per loop

In [55]: %timeit find_with_list(x,3)
1000 loops, best of 3: 618 us per loop

find item in list , and get other item from other list at same location using linq


Tag : chash , By : LUK
Date : March 29 2020, 07:55 AM
it fixes the issue correct me if i am wrong are you looking for the index of the item you searched in first list and then use the same index to retrieve from other list
If yes Try this
var testFirstList = myListCollectionObj.firstList.Where(x => x == 3).FirstOrDefault(); //then i want to get "33", and 333 from secondList and thirdList respectively
var index = myListCollectionObj.firstList.IndexOf(testFirstList);

How to find all the indexes of a recurring item in a list? (Python)


Tag : python , By : MrSparky
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Binary patch-generation in C#
  • Tab Escape Character?
  • When do Request.Params and Request.Form differ?
  • The imported project "C:\Microsoft.CSharp.targets" was not found
  • Numeric Data Entry in WPF
  • Print a Winform/visual element
  • C# logic order and compiler behavior
  • When to use an extension method with lambda over LINQtoObjects to filter a collection?
  • How to make a button appear as if it is pressed?
  • C# and Arrow Keys
  • How do you resolve a domain name to an IP address with .NET/C#?
  • Should the folders in a solution match the namespace?
  • How can I evaluate C# code dynamically?
  • CSharpCodeProvider Compilation Performance
  • How can I create Prototype Methods (like JavaScript) in C#.Net?
  • DataTable Loop Performance Comparison
  • CSV string handling
  • What is the best way to do unit testing for ASP.NET 2.0 web pages?
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com