Compare two sets of strings and then return whole strings that are different in Python 3.4 -


I am writing a small API listening program, and I'm trying to figure out that something new has been published. is. I have got more information about this, but I have a problem in the final stage - where I want to print something new. I can compare two lists of objects in the form of set and get the set of characters in the correct answer, but I can not seem to print the actual string.

A list of two lists (both new_revised_stuff and old_revised_stuff strings, like "Bob likes to eat

 
  / code>  

returns:

  set ('b', 'o', 'l' ...)  

I can get rid of 'set' notation by writing:

  list (new_stuff)  

but it does not really help. I like "Bob likes ..." if this is a new line I have also tried:

  new_stuff = [] for a new_revvisest_stuff: B in old_revvisest_stuff: if a! = B: '' .join ( A) New_straf.append (A)  

Which result is in the actual stack overflow, then it is clearly bad code.

< Div class = "post-text" itemprop = "text">

If you want to join any string of single characters in a string, then you do so ''. To join (new_stuff) . For example:

  & gt; & Gt; & Gt; New_stuff = ['B', 'O', 'L']> gt; & Gt; & Gt; However, there are two problems here, which are built in your design:  
  • The group only holds unique elements. Therefore, if your string is diffs "hello, bob" , then only o and being set < / Em>
  • Therefore, if your string diffs "likes Bob" , then change it into a set and Then back to a string you get something like 'kioboBls' .

If any of these problems are (and I suspect that they are), then you have to reconsider your algorithm. You can solve another by using OrderedSet ( collections docs in it), but the first one is going to be more of a problem. / P>

So, how can be? do you do this?

OK, you really do not need new_revised_stuff ; If you iterate over the characters and keep only those people who are not in old_revised_stuff , as long as old_revised_stuff is a set, which can be divided into two sets Any duplicate from a set will end, which I do not think you want is actually a "multiset" in Python, which is similar to

but old_revised_stuff The best way to represent it is usually the counter .

So, I think what you want (probably) is something like this:

 To snack at http://bobsburgers.com  old_string = '' New_string = 'Bob likes to eat old on http://bobsburgers.com' old_chars = collections.Counter (old_string) new_chars = [] new_string for ch: if old_chars [c]: old_church [ca] - = 1 other: New_upload.append (ca) new_string = '' .join (newmers)  

Comments

Popular posts from this blog

c# - NewtonSoft JArray - how to select multiple elements with LINQ -

c# - Process.Kill() returns access denied -

c# - Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments -