473,387 Members | 3,787 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,387 software developers and data experts.

Recalling Lists

26
If you have a text file that say has a list of 1000 plus words is there a way that you can recall that file without having to type the whole list out word by word and which will also allow you to once recalled sort the list and do other things to it
Jun 10 '07 #1
2 1497
ilikepython
844 Expert 512MB
If you have a text file that say has a list of 1000 plus words is there a way that you can recall that file without having to type the whole list out word by word and which will also allow you to once recalled sort the list and do other things to it
What do you mean? Is it something like this?:

text.txt
Expand|Select|Wrap|Line Numbers
  1. word1, word2, word3 ...,
  2. word4, word5, word6 ...
  3.  
Expand|Select|Wrap|Line Numbers
  1. inFile = file("test.txt")
  2. wordlist = [word.strip() for word in inFile.read().split(",")]
  3. wordlist.sort()
  4.  
Jun 10 '07 #2
bartonc
6,596 Expert 4TB
If you have a text file that say has a list of 1000 plus words is there a way that you can recall that file without having to type the whole list out word by word and which will also allow you to once recalled sort the list and do other things to it
Yep. Presuming that each word is on its own line followed by some sort of line-terminator (new-line):
Expand|Select|Wrap|Line Numbers
  1. fileName = r"C:\this\is\a\path\theFile.txt"
  2. # I just make up variable names, you can use you own
  3. inputFile = open(fileName)
  4. wordList = inputFile.readlines()
  5. inputFile.close()
  6. wordList.sort()
  7.  
  8. # Writing is just as easy, just open a file in (w)rite mode
  9. fileName = "whatever"
  10. outputFile = open(fileName, "w")
  11. outputFile.writelines(wordList)
  12. outputFile.close()
Which would, of course, keep the new-line chrs with each word.
Jun 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
3
by: s_subbarayan | last post by:
Dear all, 1)In one of our implementation for an application we are supposed to collate two linked lists.The actual problem is like this: There are two singularly linked lists, the final output...
1
by: Simon Forman | last post by:
I've got a function that I'd like to improve. It takes a list of lists and a "target" element, and it returns the set of the items in the lists that appear either before or after the target...
5
by: the other john | last post by:
I want to insert a record into a DB and then immediately recall what the ID is. I have heard that there is a way to do this with SQL Server (although I haven't done it yet). Unfortunately this is...
17
by: Gal Diskin | last post by:
Hi, I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print "do something with", x1, x2, x3 What I...
16
by: Michael M. | last post by:
How to find the longst element list of lists? I think, there should be an easier way then this: s1 = s2 = s3 = if len(s1) >= len(s2) and len(s1) >= len(s3): sx1=s1 ## s1 ist längster
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
0
by: Joeyeti | last post by:
Hi fellow VB knowers (I am but a learner still). I have a question for you which I struggle with. I need to convert nested Lists in MS WORD (whether numbered or bulleted or mixed) from their...
3
by: Qbert16 | last post by:
Hi, I'm quite new to python and am looking for help with lists inside lists This is an example I'm trying to do. I have the following thesaurus set... thesaurus = , ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.