Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions strings/anagram-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# function to check if two strings are
# anagram or not
def check(s1, s2):

# the sorted strings are checked
if(sorted(s1)== sorted(s2)):
print("The strings are anagrams.")
else:
print("The strings aren't anagrams.")

# driver code
s1 ="listen" #String 1
s2 ="silent" #String 2
check(s1, s2)
17 changes: 17 additions & 0 deletions strings/k-frequent-words.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Python program to find the k most frequent words
# from data set
from collections import Counter

data_set = "" #Enter long string or paragraph here

# split() returns list of all the words in the string
split_it = data_set.split()

# Pass the split_it list to instance of Counter class.
Counter = Counter(split_it)

# most_common() produces k frequently encountered
# input values and their respective counts.
most_occur = Counter.most_common(4)

print(most_occur)
24 changes: 24 additions & 0 deletions strings/pattern-match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# A Python program to demonstrate working
# of re.match().
import re

# a sample function that uses regular expressions
# to find month and day of a date.
def findMonthAndDate(string):

regex = r"([a-zA-Z]+) (\d+)"
match = re.match(regex, string)

if match == None:
print "Not a valid date"
return

print "Given Data: %s" % (match.group())
print "Month: %s" % (match.group(1))
print "Day: %s" % (match.group(2))


# Driver Code
findMonthAndDate("" #Enter pattern to match)
print("")
findMonthAndDate("") #Enter string
12 changes: 12 additions & 0 deletions strings/substring-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# function to check if small string is
# there in big string
def check(string, sub_str):
if (string.find(sub_str) == -1):
print("NO")
else:
print("YES")

# driver code
string = "" #Enter string
sub_str ="" #Enter sub string
check(string, sub_str)
28 changes: 28 additions & 0 deletions strings/vowel-count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Python3 code to count vowel in
# a string using set

# Function to count vowel
def vowel_count(str):

# Intializing count variable to 0
count = 0

# Creating a set of vowels
vowel = set("aeiouAEIOU")

# Loop to traverse the alphabet
# in the given string
for alphabet in str:

# If alphabet is present
# in set vowel
if alphabet in vowel:
count = count + 1

print("No. of vowels :", count)

# Driver code
str = "" #Enter string

# Function Call
vowel_count(str)