Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Remove all duplicates words from a given sentence

from collections import Counter
 
def remov_duplicates(input):
 
    # split input string separated by space
    input = input.split(" ")
 
    # now create dictionary using counter method
    # which will have strings as key and their
    # frequencies as value
    UniqW = Counter(input)
 
    # joins two adjacent elements in iterable way
    s = " ".join(UniqW.keys())
    print (s)
 
# Driver program
if __name__ == "__main__":
    input = 'Python is great and Java is also great'
    remov_duplicates(input)
Comment

delete repeated words in string

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main ()
{
	char str[100], word[100], twoD[10][30];
	int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, l = 0;
 
	printf ("Enter the string
");
	gets (str);
 
	// let us convert the string into 2D array
	for (i = 0; str[i] != ''; i++)
	{
		if (str[i] == ' ')
		{
			twoD[k][j] = '';
			k ++;
			j = 0;
		}
		else
		{
			twoD[k][j] = str[i];
			j ++;
		}
	}
 
	twoD[k][j] = '';
 
	j = 0;
	for (i = 0; i < k; i++)
	{
		int present = 0;
		for (l = 1; l < k + 1; l++)
		{
			if (twoD[l][j] == '' || l == i)
			{
				continue;
			}
 
			if (strcmp (twoD[i], twoD[l]) == 0) {
				twoD[l][j] = '';
				present = present + 1;
			}
		}
		// if (present > 0)	     | uncomment this `if` block if you
		// {			     | want to remove all the occurrences 
		// 	twoD[i][j] = '';   | of the words including the word
		// }			     | itself.
	}
 
	j = 0;
 
	for (i = 0; i < k + 1; i++)
	{
		if (twoD[i][j] == '')
			continue;
		else
			printf ("%s ", twoD[i]);
	}
 
	printf ("
");
 
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Python :: destroy trigger python 
Python :: adding if statements in pyhton with tuple 
Python :: #finding the differences between setA and SetB: 
Python :: python regex get start end indices for searching word 
Python :: index operator with if and elif statement in python 
Python :: dadfa 
Python :: merge python list items by index one after one 
Python :: pandas mask string contains 
Python :: 2d arrary.push in python 
Python :: pillow update image 
Python :: sns nan matrix 
Python :: sum of two diagonals in matrix 
Python :: counter vectriozer in python 
Python :: def LinearSearch(array, n, k): 
Python :: pandas difference of consecutive values 
Python :: Method to get column average 
Python :: python method name 
Python :: jama python rest api 
Python :: how to use wbtools in python 
Python :: dask dataframe csv tutorial 
Python :: falcon 900 price 
Python :: what is horse riding sport name 
Python :: jupyter_ascending 
Python :: add many instances to related field manytoamny django] 
Python :: python generate fibonacci series 
Python :: Horizontal bar graph OO interface 
Python :: python for loop start at index with enumerate 
Python :: import sys locate python = sys.exec_prefix print(locate python) 
Python :: mechanize python #8 
Python :: store array to nii file 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =