Python - buscar las palabras no repetidas

 
Vista:
sin imagen de perfil

buscar las palabras no repetidas

Publicado por Santiago (3 intervenciones) el 12/05/2017 19:27:34
Tengo que analizar un texto por ejemplo:
This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever. You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.net


Title: The Adventures of Sherlock Holmes

Author: Arthur Conan Doyle

Posting Date: April 18, 2011 [EBook #1661]
First Posted: November 29, 2002


Y de ahí sacar las palabras que no estan repetidas! Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 2.239
Plata
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

buscar las palabras no repetidas

Publicado por xve (1646 intervenciones) el 13/05/2017 12:05:17
Hola Santiago, aquí tienes un simple ejemplo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-
import collections
 
cadena="""This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever. You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.net


Title: The Adventures of Sherlock Holmes

Author: Arthur Conan Doyle

Posting Date: April 18, 2011 [EBook #1661]
First Posted: November 29, 2002"""
 
# obtenemos un array con todas las palabras
palabras=cadena.split()
 
# devolvemos únicamente las palabras no repetidas
print ([x for x, y in collections.Counter(palabras).items() if y == 1])
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

buscar las palabras no repetidas

Publicado por Santiago (3 intervenciones) el 14/05/2017 02:18:25
Muchas gracias! muy amable
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar