Given a length k string,i want to search for 2 substrings (overlap
possible) in a list consisting of length k-1 strings. These 2 substrings
when 'united' give the original string.
e.g given 'abc' i want to search in the list of 2-length strings
['ab',ac','cd',' bc','bd'] to extract either
1) 'ab and 'ac' OR ('a' common)
2) 'ab' and 'bc' OR ('b' common)
3) 'ac' and 'bc' ('c' common)
In all these cases, one of the letter is common in the 2 strings.
Out of the k-1 letters in each length k-1 string,k-2 will be common.
Another e.g is:
Given 'abcd' and list ['abc,'abd','bcd '],i must extract
1)abc and abd OR ('ab' common)
2)abc and bcd OR
3)abd and bcd OR
Here 2 letters are common in all the solutions.
I havent been able to figure out a method. Pleeez help!!
Thanks in advance,
girish 3 2181
Girish Sahani schrieb: Given a length k string,i want to search for 2 substrings (overlap possible) in a list consisting of length k-1 strings. These 2 substrings when 'united' give the original string. e.g given 'abc' i want to search in the list of 2-length strings ['ab',ac','cd',' bc','bd'] to extract either 1) 'ab and 'ac' OR ('a' common) 2) 'ab' and 'bc' OR ('b' common) 3) 'ac' and 'bc' ('c' common)
Here is a simple brute force solution that also works for different
lengths of your strings:
complete = 'abc'
partial = ['ab','ac','cd', 'bc','bd']
for i1, s1 in enumerate(parti al):
for s2 in partial[i1+1:]:
if set(s1).union(s et(s2)) == set(complete):
print s1, s2
-- Christoph
I want to generate all substrings of size k-1 from a string of size k.
e.g 'abcd' should give me ['abc','abd','bc d','acd']
Order of these strings in the list doesnt matter.
Also order doesnt matter inside the string e.g 'abc' or 'bca' or 'bac' is
the same.
I wrote the following code but it doesnt give the full output:
subsetList = []
for element in prunedNew:
for i in range(0,2):
subsetList.appe nd(element[i:i+len(element )-1])
continue
continue
return prunedNew
Thanks in Advance,
girish
Girish Sahani wrote: I want to generate all substrings of size k-1 from a string of size k. e.g 'abcd' should give me ['abc','abd','bc d','acd']
def get_sub_set( s ) :
return [s[:i]+s[i+1:] for i in range(len(s))] print get_sub_set( 'abcd' )
['bcd', 'acd', 'abd', 'abc']
Regards
Sreeram
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEhPFyrgn 0plK5qqURAoMaAK C7oRnEPkQKMeX5x hz2eXhH4pSlTQCg p8Qu
gPiJ3A029tq5jgA JI33DLUY=
=3E6C
-----END PGP SIGNATURE----- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: gyromagnetic |
last post by:
Hi,
I have written a function that searches a text string for various
words. The text is searched using a boolean 'and' or a boolean 'or' of
the input list of search terms.
Since I need to use this function for many long strings and many
search words, I would like to use as efficient a method as possible.
Are there improvements that can be made to the code below? Are there
better alternatives?
|
by: spam |
last post by:
Is there a well-known algorithm for replacing many substrings in a
string? For example, I'd like to take the string "abc def ghi jkl mno
pqr" and replace, say, every instance of "abc", "ghi", and "mno" with
another value.
Of course the brute-force approach is straight forward. Just iterate
over the full string N times (once for "abc", "ghi", and "mno"), find
all instances, and replace them using the normal std::string member...
|
by: M |
last post by:
Hi,
I've searched through the previous posts and there seems to be a few
examples of search and replacing all occurrances of a string with
another string.
I would have thought that the code below would work...
string gsub(const string & sData,
const string & sFrom,
|
by: Amit Khemka |
last post by:
Hello All,
say you have some string: ", foobar "
Now i want to extract all substrings for which
"isinstance(eval(substr), list)" is "True" .
now one way is to walk through the whole sample string and check the
condition, I
was wondering if there is any smarter way of doing the same, may be
using regular-expressions.
|
by: Steven Bethard |
last post by:
I've got a list of word substrings (the "tokens") which I need to align
to a string of text (the "sentence"). The sentence is basically the
concatenation of the token list, with spaces sometimes inserted beetween
tokens. I need to determine the start and end offsets of each token in
the sentence. For example::
py> tokens =
py> text = '''\
.... She's gonna write
.... a book?'''
| |
by: Martien van Wanrooij |
last post by:
I have been using phpdig in some websites but now I stored a lot of larger
texts into a mysql database. In the phpdig search engine, when you entered a
search word, the page where the search word was found was displayed with
about 2 lines before and 2 lines behind the search word itself. Let us say
you look for "peanut butter" an the word is found in a larger text about
sandwiches, even when it is on the 40th line of the text you would get...
|
by: girish |
last post by:
Hi,
I want to generate all non-empty substrings of a string of length >=2.
Also,
each substring is to be paired with 'string - substring' part and vice
versa.
Thus, gives me , , , , , ] etc.
Similarly, 'abcd' should give me , , , , , ,, ,
, , , , ,]
I've tried the following but i cant prevent duplicates and i'm missing
|
by: google |
last post by:
I need a simple wildcard pattern matching function written in JS. I
have wrestled with regular expresions but frankly am struggling to come
up with anything less than an epic function of many lines of code ...
Any help much appreciated!
Sample string :
"the cat sat on the mat"
matches :
"the cat*" , "*cat*" , "*the mat"
|
by: Helmut Jarausch |
last post by:
Hi,
I'm looking for an elegant solution to the following (quite common)
problem:
Given a string of substrings separated by white space,
split this into tuple/list of elements.
The problem are quoted substrings like
abc "xy z" "1 2 3" "a \" x"
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |