Word Count

This program asks the user for a word which will be your search word and the name of a file to open and search for that word. Then create a function that will receive two parameters (both string) representing those two data points. This function returns the number of occurrences of that word in that file.

WSQ12WSQ12-2

 

WSQ12 /Contador de palabras

Realmente no sé si es válido lo que hice, pero funcionó Bl. o eso creo. jej

Primero, me quebré demasiado la cabeza buscando algún programa en particular que contara las palabras de un texto. Algunos lo hacían, otros no les entendí y no iba a poner algo que no entendiera ni .. :#  Finalmente me despejé -en la clase de aev, no quería hacer mi ensayo- y comencé a buscar cosas en especifico.

Datos encontrados búsqueda 1 -fallida-

lazy

Split (): Separa toda una oración en pedazos. Si no se separa en la frase con un espacio, no lo dividirá.

Iba a importar un modulo “collections” que contiene un counter -cuenta las veces que aparece algo en una lista-

Descubrí que se pueeeeeede hacer de diferentes maneras, pero aun no encontraba la mía Bl pero basta de choro.

Primeramente:

Se necesita hacer uno o varios textos previos, pero estos -preferentemente- deben estar ubicados en la misma carpeta, yo los hice en un bloc de notas y ya.

Después abrirlos desde python. para esto utilicé el “with open(texto, “rt”) as Txt:” explicando esto; para abrir un archivo de texto en python es necesario abrirlo y cerrarlo, esto se puede hacer con un simple open(texto, “tipo”) y después se debe cerrar, como para guardar los cambios, pero como antes de eso descubrí el with, lo usé. despues con un “.lower()” se convierte todo en minusculas (texto) para que Las=las . Esto también lo repetí cuando pedí la palabra al usuario, por si se le ocurre escribir en mayusculas.

Al principio de todo el programa, puse la función de contador, que contará las veces que apareció una palabra en el texto. Para contar las veces usé algo similar al counter que había encontrado antes del modulo collections, pero no tuve que importar nada. Solo se pone el nombre

count
2016-03-31 (4)

Continue reading “WSQ12 /Contador de palabras”

The Needle in the Haystack (WSQ12)

Photograph credit

This program was really hard to make. I think that is because we have never worked with something other than the monitor to run our programs. Now we had to involve a text file. I started this program on friday and all I have been doing is this, I finally finished and I want  to help you guys so it doesn’t take you so long. I think I easily read like 6 webpages, checked in 4 books and watched 7 youtube videos to find out how to do this program. That was the thing that consumed most of my time.

I’m gonna save your time and tell you the information that was helpful. My tutorial is divided in three sections: the first is just an introduction, the second is how to find a word in a string and the third is how to find the word in a whole text file. First you need to know how to open, close, input and output to a file. for that check out this page. Then you need to know how to work with strings to find a word in it. And the rest is to use your brain for the logic of the program. I looked in so many places really, but there was one book that had THE ANSWERS TO ALL MY PROBLEMS, I wish I had looked there in the first place. AND WHERE IS THIS BOOK?! Well.. believe it or not, it’s the book for our course. Yeah I know, who would have known. This is the first time I look at it. In my tutorial I explain how to get it but you can just press this link and download the PDF.

As usual here is my code:

WordCountText.cpp

WordCountString.cpp

And here are the

Continue reading “The Needle in the Haystack (WSQ12)”

The Needle in the Haystack (WSQ12)

Photograph credit

This program was really hard to make. I think that is because we have never worked with something other than the monitor to run our programs. Now we had to involve a text file. I started this program on friday and all I have been doing is this, I finally finished and I want  to help you guys so it doesn’t take you so long. I think I easily read like 6 webpages, checked in 4 books and watched 7 youtube videos to find out how to do this program. That was the thing that consumed most of my time.

I’m gonna save your time and tell you the information that was helpful. My tutorial is divided in three sections: the first is just an introduction, the second is how to find a word in a string and the third is how to find the word in a whole text file. First you need to know how to open, close, input and output to a file. for that check out this page. Then you need to know how to work with strings to find a word in it. And the rest is to use your brain for the logic of the program. I looked in so many places really, but there was one book that had THE ANSWERS TO ALL MY PROBLEMS, I wish I had looked there in the first place. AND WHERE IS THIS BOOK?! Well.. believe it or not, it’s the book for our course. Yeah I know, who would have known. This is the first time I look at it. In my tutorial I explain how to get it but you can just press this link and download the PDF.

As usual here is my code:

WordCountText.cpp

WordCountString.cpp

And here are the

Continue reading “The Needle in the Haystack (WSQ12)”