473,840 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the split command in a list

26 New Member
If you have a list how do you use the split command to split each line into word, and freqency?
Jun 10 '07
14 39974
bartonc
6,596 Recognized Expert Expert
Ok, this is kind of making sense so once I have pulled out say the three longest, shortest, and middle words what syntax do I use to tell it to take those words and split each word onto a line listing the frequency or number of times each of the words occurs in the list.
I s'pose you could use some complicated method of keeping track, or you can just do this:
Expand|Select|Wrap|Line Numbers
  1. >>> anStr = "The fat cat ran into a fat cow"
  2. >>> anStr.count("fat")
  3. 2
  4. >>> 
Basically, in Python, any time you think that an object should/could have a certain functionality, just go to the interactive interpreter and try it. (This is exactly what I have done above). If it doesn't work, then turn to the Docs. If that fails, well, you know - ask somebody.
Jun 11 '07 #11
bartonc
6,596 Recognized Expert Expert
I s'pose you could use some complicated method of keeping track, or you can just do this:
Expand|Select|Wrap|Line Numbers
  1. >>> anStr = "The fat cat ran into a fat cow"
  2. >>> anStr.count("fat")
  3. 2
  4. >>> 
Basically, in Python, any time you think that an object should/could have a certain functionality, just go to the interactive interpreter and try it. (This is exactly what I have done above). If it doesn't work, then turn to the Docs. If that fails, well, you know - ask somebody.
Sorry, I forgot that we were working on lists:
Expand|Select|Wrap|Line Numbers
  1. >>> aList = anStr.split()
  2. >>> aList
  3. ['The', 'fat', 'cat', 'ran', 'into', 'a', 'fat', 'cow']
  4. >>> aList.count('fat')
  5. 2
  6. >>> 
Jun 12 '07 #12
texas22
26 New Member
Is there a way I can use a three dimensional array that will output the number of times a word appears in a list where in len in the first, the words in the second, and the frequency in the third?
Jun 12 '07 #13
Smygis
126 New Member
Is there a way I can use a three dimensional array that will output the number of times a word appears in a list where in len in the first, the words in the second, and the frequency in the third?
something like:


Expand|Select|Wrap|Line Numbers
  1. thing = [[len(word), word, listOfWords.count(word)] for word in listOfWords]
  2.  
Jun 12 '07 #14
texas22
26 New Member
Thanks for the help that helped make sense of it
Jun 12 '07 #15

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

Similar topics

2
22729
by: Kevin | last post by:
Hi All, I am new to MS SQL Server.I am using MS SQL 2000.I have a problem in creating a table by using Select command.I have table called "test" and i want to create another table with the same structure and rows.I tried with the following command create Table test1 as select * from test; But it give an syntax error.I have tried the same command in Oracle
0
1646
by: Nitin Gaur | last post by:
Hi, I am developing an application using Visual Studio .NET in C++. I am using following command to automate the debugging of this executable: devenv -command Debug.StepInto myProg.cpp -debugexe myProg.exe The switch "-command" with option "Debug.StepInto" actually opens up the "Debug" toolbar menu and clicks on "Step Into" item in it. It opens up a "Save File As" dialog for saving "myprog.sln" file. I want to get rid of
3
14628
by: NK | last post by:
Hello, I am a beginner of DB2 and I am in a trouble that I can't access to sample database. Please see below. ENV : OS AIX-5.2/ DB2 8.1.2 SYMPTOM: I don't have any DB2 client terminal so far and all the troubles
1
12850
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
1
3754
by: Mike P | last post by:
I am using Split to split get a number of items from a multi line text box. But I need to be able to get the number of elements within the text box (e.g. if the text box has 2,4,8 in it, I want to be able to count that this text box has 3 elements entered into it). My code is below : for (int p=0; p < dgNational.Items.Count; p++) { strQuantity = ((TextBox)dgNational.Items.FindControl("txtAccount")).Text +"\r\n";
0
6046
by: den 2005 | last post by:
Hi everybody, I am not familiar using Gridview, I created a Gridview with Edit Command Button, but when I click the update Command button this error message below is displayed, what and where is the problem? I am confused. Can anyone show me exactly to do edit process of Gridview using Edit Command button properly? Thanks. Error Message: Invalid postback or callback argument. Event validation is enabled using
10
6592
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
1
10518
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 7 2 2008 1 7 I want to...
0
3141
debasisdas
by: debasisdas | last post by:
Using Merge command (supported version 9 onwards) ======================================== Used to go for insert/update in a single command based on some condition. Example #1 merge into emp5 e using (select empno,ename from emp) e1 on (e.empno=e1.empno)
0
9861
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10924
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, 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...
1
10665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10301
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 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...
0
9444
agi2029
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...
1
7839
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 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...
0
7023
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();...
0
5874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3139
bsmnconsultancy
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...

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.