473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Lines of Strings

Hi

Suppose we have data file like this one (Consider all lines as strings )

1 2 3 3 4 4 4 4 5 6
2 2 2 5 5 5 6
3 2 1 1 1 3 3 3 4 6

I would like to remove line if its belong to another one, and will be able
to do this if longer line come after a short one.

Thanks

__________________________________________________ _______________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/g...ave/direct/01/

Sep 16 '05 #1
4 1281
Reem Mohammed wrote:
Hi

Suppose we have data file like this one (Consider all lines as strings )

1 2 3 3 4 4 4 4 5 6
2 2 2 5 5 5 6
3 2 1 1 1 3 3 3 4 6

I would like to remove line if its belong to another one, and will be
able to do this if longer line come after a short one.


That's fine. Now try and do it, and ask for help when you're in trouble.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Sep 16 '05 #2
If these were the lines what would the output look like?
From your example it doesn't appear that any of the lines
would be eliminated.

Larry Bates

Reem Mohammed wrote:
Hi

Suppose we have data file like this one (Consider all lines as strings )

1 2 3 3 4 4 4 4 5 6
2 2 2 5 5 5 6
3 2 1 1 1 3 3 3 4 6

I would like to remove line if its belong to another one, and will be
able to do this if longer line come after a short one.

Thanks

__________________________________________________ _______________
Express yourself instantly with MSN Messenger! Download today - it's
FREE! http://messenger.msn.click-url.com/g...ave/direct/01/

Sep 16 '05 #3
If these were the lines what would the output look like?
From your example it doesn't appear that any of the lines would be eliminated.

Larry Bates

Reem Mohammed wrote: Hi

Suppose we have data file like this one (Consider all lines as strings )

1 2 3 3 4 4 4 4 5 6
2 2 2 5 5 5 6
3 2 1 1 1 3 3 3 4 6

I would like to remove line if its belong to another one, and will be
able to do this if longer line come after a short one.

Thanks

__________________________________________________ _______________
Express yourself instantly with MSN Messenger! Download today - it's
FREE! http://messenger.msn.click-url.com/g...ave/direct/01/


Sep 16 '05 #4
On Thu, 15 Sep 2005, Reem Mohammed wrote:
Suppose we have data file like this one (Consider all lines as strings )

1 2 3 3 4 4 4 4 5 6
2 2 2 5 5 5 6
3 2 1 1 1 3 3 3 4 6

I would like to remove line if its belong to another one, and will be
able to do this if longer line come after a short one.


when you say "belong to another one", do you mean "is a substring of
another one"? so 4 5 6 would belong to 1 2 3 4 5 6 7 8?

if so, what you're asking for is the set of upper bounds of a partially
ordered set. i often find that i need to compute things like this; i
haven't figured out a way to do it any faster than the obvious:

def upperbounds(set, order):
"""Finds the upper bounds of a set under a partial order.

Set is an iterable (which may contain duplicates - it doesn't actually
need to be a set), and order is a function of two arguments such that
order(a, b) returns True if a is greater than b, and False otherwise.

"""
bounds = [] # this would be better as a set, really
for item in set:
for bound in bounds:
if (order(bound, item)):
break
if (order(item, bound)):
bounds.remove(bound)
else:
bounds.append(item)
return bounds

you could use this as follows:

lines = map(str.strip, inputfile.readlines())
print upperbounds(lines, str.__contains__)

tom

--
I content myself with the Speculative part [...], I care not for the Practick. I seldom bring any thing to use, 'tis not my way. Knowledge is my ultimate end. -- Sir Nicholas Gimcrack
Sep 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Douglas Alan | last post by:
Is there a canonical way of iterating over the lines of a file that are null-separated rather than newline-separated? Sure, I can implement my own iterator using read() and split(), etc., but...
5
by: Jamie Jackson | last post by:
Two fairly basic questions: I need to supply a method with an array of strings, which will eventually be used to pattern match against another array of strings. 1. Is there a good way to span...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
5
by: RSBakshi | last post by:
Can any body tell me how to find duplicate lines in C i have tried to find using Binary tree and Text files but not suceeded .. It works for Word but not for lines please help me you can...
19
by: diffuser78 | last post by:
Like in C we comment like /* Bunch of lines of code */ Should we use docstring """ """ Or there is something else too ?? Every help is appreciated.
15
by: d4 | last post by:
I have a vbscript (below) I want to rewrite in C# but I cannot get it to work (unless there is a better way to do it). The script will combine 2 lines if the (next) line contains a "+",...
0
by: Fir5tSight | last post by:
Hi, I have a TextBox, textAddress, that's defined as an array of text strings. Currently I only have a single line of text in it: textAddress.Text = "100 America Avenue, New York, NY...
1
by: Fir5tSight | last post by:
Hi, I have a TextBox, textAddress, that's defined as an array of text strings. Currently I only have a single line of text in it: textAddress.Text = "100 America Avenue, New York, NY...
9
by: paktsardines | last post by:
Dear all, As of yesterday I have this function: char ** lines = read_file("filename.txt"); Now, I want to print the contents of lines. A first attempt: int i=0;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.