logo
down
shadow

How to keep duplicates from a string[] exclude words from a List and print them out


How to keep duplicates from a string[] exclude words from a List and print them out

Content Index :

How to keep duplicates from a string[] exclude words from a List and print them out
Tag : chash , By : user186831
Date : January 11 2021, 03:34 PM

To fix the issue you can do I'd suggest the below approach (which outputs joe and salad).
The two GroupBys allow you to group the words and then work out how many instances there are of each word. OrderByDescending and First allows you to find the most common words. SelectMany then extracts those words, and Except excludes the specific words (e.g. and) that you want to exclude (the Where is to handle the edge case where textOnBook is a blank string). string.Join is used to show the contents of the List.
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{ 
    private static List<String> excludeFromText = new List<string>() {"and", "he", "the", "to", "is"};
    private static String textOnBook = "alis and joe went to the store to buy fish and salad salad is joe favorite food";


    public static void Main()
    {
        Console.WriteLine(string.Join(",", MostUsedWords(textOnBook, excludeFromText)));
    }

    public static  List<String> MostUsedWords(String textOnBook, List<String> excludeFromText)
    {
        var words = textOnBook.Split(' ');

        return words.GroupBy(z => z)
                    .GroupBy(z => z.Count())
                    .OrderByDescending(z => z.Key)
                    .First()
                    .SelectMany(z => z)
                    .Where(z => z.Length > 0)
                    .Except(excludeFromText)
                    .ToList();
     }
}

Comments
No Comments Right Now !

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

Share : facebook icon twitter icon

Compare two List<string> and print the duplicates


Tag : chash , By : Jonathan Bernard
Date : March 29 2020, 07:55 AM
With these it helps Use Enumerable.Intersect method
List<string> duplicates = list1.Intersect(list2).ToList();

Exclude words that appears in a list from a string


Tag : python , By : AnthonyC
Date : March 29 2020, 07:55 AM
should help you out I have such list: , The filter expression is wrong. Change it to:
>>> reduced = filter(lambda w: w not in stopwords, re.split(r'\W+', sentence.lower()))
>>> list(reduced)
['mule', 'eating', 'drinking']

How do you exclude words in a list of words using bash and regular expressions?


Tag : regex , By : Andrew Mattie
Date : March 29 2020, 07:55 AM
will help you You can use Bash pattern rules as a regex-like language. In particular, Bash gives special preference to $@ and $* when applying patterns - it treats them as lists of words, and applies the pattern to each item in the list.
As a result, you need to write a function (so you will have a parameter list in $@ or $*) so that you can apply the pattern over the list. You would use the %% pattern, which says "match and delete the longest possible pattern". Here's is my take on it:
$ strip_xy_cpp() {
>     RESULT="${*%%*.xy.cpp}"
>     echo "$RESULT"
> }

$ echo $MYLIST
Word1.c Word2.c Word3.xy.c Word4.cpp Word5.xy.cpp

$ NEWLIST=$( strip_xy_cpp $MYLIST )

$ echo $NEWLIST
Word1.c Word2.c Word3.xy.c Word4.cpp

regular expression, find string, exclude list of words containing string


Tag : regex , By : Josh Tegart
Date : March 29 2020, 07:55 AM
this will help I am trying to find the string "isis" but I don't want a specific list that I know it will be in, such as "crisis" I have tried this...^(?!(CRISIS|crisisid)$)[ISIS]+$ but that doesn't work, either. the strings can be any case and/or mixed case. , This is what I found that worked.
^(?!(.*crisis.*|.*isisid.*)$).*ISIS.*
XXISISIDXX --> No 
FFFISISFFF --> Yes 
NNCRISISNN --> No 
ISIS --> Yes 
XYZ --> No 
XXX ISIS CCC --> Yes 
isisid --> No 
lwisis --> Yes  

PCRE match when words but exclude a list of words within or in relation to matching words


Tag : php , By : wraith
Date : March 29 2020, 07:55 AM
wish help you to fix your issue If you have to just avoid returning milk that is part of goatmilk or goat milk, you can use (*SKIP)(*FAIL) regex:
\bgoat\s*milk\b(*SKIP)(*FAIL)|\b(?:eggs?|milk)\b
Related Posts Related QUESTIONS :
  • dynamically add images to view
  • Are static extension methods on User object safe?
  • Process thousands of database calls simultaneously
  • Trying to decrypt a string with public key(not private) using bouncycastle in .net
  • How to retrieve the name of an usb device
  • Query many-to-many related data using Entity Framework Core
  • ASP.NET MVC : how to find the view from a controller?
  • Inconsistent behaviour using Entity Framework for ASP.NET MVC app vs windows service
  • AutoFixture Customize vs Build
  • How to change textbox location at the click of a mouse in live mode?
  • How can I deserialize a XML file without defining the parent node?
  • asp.net core how decrease class coupling
  • ASP.NET Core Razor Pages Routing With parameters
  • String Escaping With $ Interpolation and @ Encoding
  • ConfigurationManager in ASP.NET WebAPI tested with HttpServer
  • Top down shooting in Unity 2D don't work as I want it to
  • Use own redirectUri when the Authentication expires
  • Using "foreach" in string array c#
  • "Object reference not set to an instance of an object" for create multiply models on one view
  • Get data passed trought pushAsync
  • Selector expression dynamic on IQueryable
  • Logut with SignInManager not calling method
  • Exit event handler with MessageBox OK button
  • Can not load view from Custom Renderer Xamarin Forms
  • Looking for a .Net ORM
  • Cost of SortedDictionary.Count
  • All possible combinations of n items selected randomly from a set of x items (algorithm)
  • Displaying process percentage on DOS screen
  • C# Importing Large Volume of Data from CSV to Database
  • c# control location precision
  • Printing to Zebra printer gives faint and blurry images
  • How to avoid stepping into dll code file?
  • Programmaticaly prevent Vista desktop search (WDS) from indexing pst files placed on mapped network drives
  • Is there anyway to reduce IsolatedStorage capacity in Silverlight?
  • C#: How to print a unicode string to console?
  • Frequency Table with Random Values
  • My Visual Studio 2008 web application keeps throwing a .Net error when I first run it, but refreshing fixes it
  • TCP Connection Creation and Closing Event Hooking
  • Find changed properties of a class
  • C#: Object with custom marshaller not containing data after PInvoke call
  • Version Control System with API. Need to get metrics
  • Performance comparison of Dictionaries
  • How to get process name and title of the top window on Windows / C#
  • How to save the ListView contents to a text file?
  • Why not .NET-style delegates rather than closures in Java?
  • Get CLSID by PIA interface Type
  • Visual Studio 2008 C# - Recover solution from application manifest possible?
  • Is a good practice to initialize private data members from within ctor by calling the associated properties instead of t
  • Inserting into a bitstream
  • How do you write byte[] array using log4.net
  • Clickonce + .NET client profile 4 framework + offline
  • Show form that showDialog from mainForm won't block it, but closing mainForm will close it
  • Developing a GPS car tracking system
  • dynamic log4net appender name?
  • Visual studio formatting issue
  • IndexOutOfRangeException when a stream is a multiple of the buffer size
  • How to deal with calculated values with Dependency Properties on a custom WPF control
  • counting from textbox,asp.net
  • Threading best practice when using SFTP in C#
  • how to load PDF file in website page using C#
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com