Description stringlengths 9 105 | Link stringlengths 45 135 | Code stringlengths 10 26.8k | Test_Case stringlengths 9 202 | Merge stringlengths 63 27k |
|---|---|---|---|---|
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # Python code
# To print even length words in string
# input string
n = "This is a python language"
# splitting the words in a given string
s = n.split(" ")
for i in s:
# checking the length of words
if len(i) % 2 == 0:
print(i)
# this code is contributed by gangarajula laxmi | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# Python code
# To print even length words in string
# input string
n = "This is a python language"
# splitting the words in a given string
s = n.split(" ")
for i in s:
# checking the length of words
if len(i) % 2 == 0:
print(i)
# this code is cont... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # Python3 program to print
# even length words in a string
def printWords(s):
# split the string
s = s.split(" ")
# iterate in words of string
for word in s:
# if length is even
if len(word) % 2 == 0:
print(word)
# Driver Code
s = "i am muskan"
printWords(s) | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# Python3 program to print
# even length words in a string
def printWords(s):
# split the string
s = s.split(" ")
# iterate in words of string
for word in s:
# if length is even
if len(word) % 2 == 0:
print(word)
# Dr... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # Python code
# To print even length words in string
# input string
n = "geeks for geek"
# splitting the words in a given string
s = n.split(" ")
l = list(filter(lambda x: (len(x) % 2 == 0), s))
print(l) | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# Python code
# To print even length words in string
# input string
n = "geeks for geek"
# splitting the words in a given string
s = n.split(" ")
l = list(filter(lambda x: (len(x) % 2 == 0), s))
print(l)
Input: s = "This is a python language"
Output: This is python... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # python code to print even length words
n = "geeks for geek"
s = n.split(" ")
print([x for x in s if len(x) % 2 == 0]) | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# python code to print even length words
n = "geeks for geek"
s = n.split(" ")
print([x for x in s if len(x) % 2 == 0])
Input: s = "This is a python language"
Output: This is python language
[END] |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # python code to print even length words
n = "geeks for geek"
s = n.split(" ")
print([x for i, x in enumerate(s) if len(x) % 2 == 0]) | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# python code to print even length words
n = "geeks for geek"
s = n.split(" ")
print([x for i, x in enumerate(s) if len(x) % 2 == 0])
Input: s = "This is a python language"
Output: This is python language
[END] |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # recursive function to print even length words
def PrintEvenLengthWord(itr, list1):
if itr == len(list1):
return
if len(list1[itr]) % 2 == 0:
print(list1[itr])
PrintEvenLengthWord(itr + 1, list1)
return
str = "geeks for geek"
l = [i for i in str.split()]
PrintEvenLengthWord(0, l) | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# recursive function to print even length words
def PrintEvenLengthWord(itr, list1):
if itr == len(list1):
return
if len(list1[itr]) % 2 == 0:
print(list1[itr])
PrintEvenLengthWord(itr + 1, list1)
return
str = "geeks for geek"
l = [... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | s = "geeks for geek"
# Split the string into a list of words
words = s.split(" ")
# Use the filter function and lambda function to find even length words
even_length_words = list(filter(lambda x: len(x) % 2 == 0, words))
# Print the list of even length words
print(even_length_words)
# This code is contributed by Edu... | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
s = "geeks for geek"
# Split the string into a list of words
words = s.split(" ")
# Use the filter function and lambda function to find even length words
even_length_words = list(filter(lambda x: len(x) % 2 == 0, words))
# Print the list of even length words
prin... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | import itertools
s = "geeks for geek"
# Split the string into a list of words
words = s.split(" ")
# Use the itertools.filterfalse function and lambda function to find even length words
even_length_words = list(itertools.filterfalse(lambda x: len(x) % 2 != 0, words))
# Print the list of even length words
print(even... | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
import itertools
s = "geeks for geek"
# Split the string into a list of words
words = s.split(" ")
# Use the itertools.filterfalse function and lambda function to find even length words
even_length_words = list(itertools.filterfalse(lambda x: len(x) % 2 != 0, wor... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # code
def print_even_length_words(s):
words = s.replace(",", " ").replace(".", " ").split()
for word in words:
if len(word) % 2 == 0:
print(word, end=" ")
s = "geeks for geek"
print_even_length_words(s) | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# code
def print_even_length_words(s):
words = s.replace(",", " ").replace(".", " ").split()
for word in words:
if len(word) % 2 == 0:
print(word, end=" ")
s = "geeks for geek"
print_even_length_words(s)
Input: s = "This is a python lan... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | # Initialize the input string
s = "This is a python language"
# Initialize an empty string variable to store the current word being parsed
word = ""
# Iterate over each character in the input string
for i in s:
# If the character is a space, it means the current word has ended
if i == " ":
# Check if ... | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
# Initialize the input string
s = "This is a python language"
# Initialize an empty string variable to store the current word being parsed
word = ""
# Iterate over each character in the input string
for i in s:
# If the character is a space, it means the curre... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | from itertools import compress
n = "This is a python language"
s = n.split(" ")
even_len_bool = [len(word) % 2 == 0 for word in s]
even_len_words = list(compress(s, even_len_bool))
print(even_len_words) | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
from itertools import compress
n = "This is a python language"
s = n.split(" ")
even_len_bool = [len(word) % 2 == 0 for word in s]
even_len_words = list(compress(s, even_len_bool))
print(even_len_words)
Input: s = "This is a python language"
Output: This is python ... |
Python program to print even length words in a string | https://www.geeksforgeeks.org/python-program-to-print-even-length-words-in-a-string/ | s = "I am omkhar"
word_start = 0
even_words = []
for i in range(len(s)):
if s[i] == " ":
word_end = i
word_length = word_end - word_start
if word_length % 2 == 0:
even_words.append(s[word_start:word_end])
word_start = i + 1
word_length = len(s) - word_start
if word_len... | Input: s = "This is a python language"
Output: This is python language | Python program to print even length words in a string
s = "I am omkhar"
word_start = 0
even_words = []
for i in range(len(s)):
if s[i] == " ":
word_end = i
word_length = word_end - word_start
if word_length % 2 == 0:
even_words.append(s[word_start:word_end])
word_start ... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | # Python3 code to demonstrate working of
# Uppercase Half String
# Using upper() + loop + len()
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
hlf_idx = len(test_str) // 2
res = ""
for idx in range(len(test_str)):... | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
# Python3 code to demonstrate working of
# Uppercase Half String
# Using upper() + loop + len()
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
hlf_idx = len(test_str) // 2
res = ""... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | # Python3 code to demonstrate working of
# Uppercase Half String
# Using list comprehension + join() + upper()
# Initializing string
test_str = "geeksforgeeks"
# Printing original string
print("The original string is : " + str(test_str))
# Computing half index
hlf_idx = len(test_str) // 2
# join() used to create re... | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
# Python3 code to demonstrate working of
# Uppercase Half String
# Using list comprehension + join() + upper()
# Initializing string
test_str = "geeksforgeeks"
# Printing original string
print("The original string is : " + str(test_str))
# Computing half index
hlf_idx = len(test_str)... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | # Python3 code to demonstrate working of
# Uppercase Half String
# Using upper() + slicing string
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
hlf_idx = len(test_str) // 2
# Making new string with half upper cas... | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
# Python3 code to demonstrate working of
# Uppercase Half String
# Using upper() + slicing string
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
hlf_idx = len(test_str) // 2
# Maki... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | # Python3 code to demonstrate working of
# Uppercase Half String
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
x = len(test_str) // 2
a = test_str[x:]
b = test_str[:x]
cap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
sma = "abc... | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
# Python3 code to demonstrate working of
# Uppercase Half String
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
x = len(test_str) // 2
a = test_str[x:]
b = test_str[:x]
cap = "ABCDE... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | import re
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
hlf_idx = len(test_str) // 2
# Making new string with half upper case using regular expressions
res = re.sub(r"(?i)(\w+)", lambda m: m.group().upper(), test... | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
import re
# initializing string
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
# computing half index
hlf_idx = len(test_str) // 2
# Making new string with half upper case using regular expressions
res = re.sub(r"(?i)(\w+)", ... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | # Python3 code to demonstrate working of
# Uppercase Half String
# Using string concatenation and conditional operator
# Iializing string
test_str = "geeksforgeeks"
# Printing original string
print("The original string is : " + str(test_str))
# Computing half index
length = len(test_str)
hlf_idx = length // 2
# Ini... | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
# Python3 code to demonstrate working of
# Uppercase Half String
# Using string concatenation and conditional operator
# Iializing string
test_str = "geeksforgeeks"
# Printing original string
print("The original string is : " + str(test_str))
# Computing half index
length = len(test_... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | from itertools import islice
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
hlf_idx = len(test_str) // 2
res = "".join(
[c.upper() if i >= hlf_idx else c for i, c in enumerate(islice(test_str, None))]
)
# printing result
print("The resultant string : " +... | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
from itertools import islice
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
hlf_idx = len(test_str) // 2
res = "".join(
[c.upper() if i >= hlf_idx else c for i, c in enumerate(islice(test_str, None))]
)
# printing result
... |
Python - Uppercase Half String | https://www.geeksforgeeks.org/python-uppercase-half-string/ | test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
hlf_idx = len(test_str) // 2
res = "".join(map(lambda c: c.upper() if test_str.index(c) >= hlf_idx else c, test_str))
# printing result
print("The resultant string : " + str(res)) | #Input : test_str = 'geeksforgeek'??????
#Output : geeksfORGE | Python - Uppercase Half String
test_str = "geeksforgeeks"
# printing original string
print("The original string is : " + str(test_str))
hlf_idx = len(test_str) // 2
res = "".join(map(lambda c: c.upper() if test_str.index(c) >= hlf_idx else c, test_str))
# printing result
print("The resultant string : " + str(res))... |
Python program to capitalize the first and last character of each word in a string | https://www.geeksforgeeks.org/python-program-to-capitalize-the-first-and-last-character-of-each-word-in-a-string/ | # Python program to capitalize
# first and last character of
# each word of a String
# Function to do the same
def word_both_cap(str):
# lambda function for capitalizing the
# first and last letter of words in
# the string
return " ".join(map(lambda s: s[:-1] + s[-1].upper(), s.title().split()))
# D... | Input: hello world
Output: HellO WorlD | Python program to capitalize the first and last character of each word in a string
# Python program to capitalize
# first and last character of
# each word of a String
# Function to do the same
def word_both_cap(str):
# lambda function for capitalizing the
# first and last letter of words in
# the string
... |
Python program to capitalize the first and last character of each word in a string | https://www.geeksforgeeks.org/python-program-to-capitalize-the-first-and-last-character-of-each-word-in-a-string/ | # Python program to capitalize
# first and last character of
# each word of a String
s = "welcome to geeksforgeeks"
print("String before:", s)
a = s.split()
res = []
for i in a:
x = i[0].upper() + i[1:-1] + i[-1].upper()
res.append(x)
res = " ".join(res)
print("String after:", res) | Input: hello world
Output: HellO WorlD | Python program to capitalize the first and last character of each word in a string
# Python program to capitalize
# first and last character of
# each word of a String
s = "welcome to geeksforgeeks"
print("String before:", s)
a = s.split()
res = []
for i in a:
x = i[0].upper() + i[1:-1] + i[-1].upper()
res.app... |
Python program to check if a string has at least one letter and one number | https://www.geeksforgeeks.org/python-program-to-check-if-a-string-has-at-least-one-letter-and-one-number/ | def checkString(str):
# initializing flag variable
flag_l = False
flag_n = False
# checking for letter and numbers in
# given string
for i in str:
# if string has letter
if i.isalpha():
flag_l = True
# if string has number
if i.isdigit():
... | Input: welcome2ourcountry34
Output: True | Python program to check if a string has at least one letter and one number
def checkString(str):
# initializing flag variable
flag_l = False
flag_n = False
# checking for letter and numbers in
# given string
for i in str:
# if string has letter
if i.isalpha():
flag_l... |
Python program to check if a string has at least one letter and one number | https://www.geeksforgeeks.org/python-program-to-check-if-a-string-has-at-least-one-letter-and-one-number/ | def checkString(str):
# initializing flag variable
flag_l = False
flag_n = False
# checking for letter and numbers in
# given string
for i in str:
# if string has letter
if i in "abcdefghijklmnopqrstuvwxyz":
flag_l = True
# if string has number
if i ... | Input: welcome2ourcountry34
Output: True | Python program to check if a string has at least one letter and one number
def checkString(str):
# initializing flag variable
flag_l = False
flag_n = False
# checking for letter and numbers in
# given string
for i in str:
# if string has letter
if i in "abcdefghijklmnopqrstuvwxy... |
Python program to check if a string has at least one letter and one number | https://www.geeksforgeeks.org/python-program-to-check-if-a-string-has-at-least-one-letter-and-one-number/ | import operator as op
def checkString(str):
letters = "abcdefghijklmnopqrstuvwxyz"
digits = "0123456789"
# initializing flag variable
flag_l = False
flag_n = False
# checking for letter and numbers in
# given string
for i in str:
# if string has letter
if op.countOf(l... | Input: welcome2ourcountry34
Output: True | Python program to check if a string has at least one letter and one number
import operator as op
def checkString(str):
letters = "abcdefghijklmnopqrstuvwxyz"
digits = "0123456789"
# initializing flag variable
flag_l = False
flag_n = False
# checking for letter and numbers in
# given stri... |
Python program to check if a string has at least one letter and one number | https://www.geeksforgeeks.org/python-program-to-check-if-a-string-has-at-least-one-letter-and-one-number/ | import re
def checkString(str):
# using regular expression to check if a string contains
# at least one letter and one number
match = re.search(r"[a-zA-Z]+", str) and re.search(r"[0-9]+", str)
if match:
return True
else:
return False
# driver code
print(checkString("thishasboth29... | Input: welcome2ourcountry34
Output: True | Python program to check if a string has at least one letter and one number
import re
def checkString(str):
# using regular expression to check if a string contains
# at least one letter and one number
match = re.search(r"[a-zA-Z]+", str) and re.search(r"[0-9]+", str)
if match:
return True
... |
Python program to check if a string has at least one letter and one number | https://www.geeksforgeeks.org/python-program-to-check-if-a-string-has-at-least-one-letter-and-one-number/ | def checkString(str):
# Create sets of letters and digits
letters = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
digits = set("0123456789")
# Check if the intersection of the input string and the sets of letters and digits is not empty
return bool(letters & set(str)) and bool(digits &... | Input: welcome2ourcountry34
Output: True | Python program to check if a string has at least one letter and one number
def checkString(str):
# Create sets of letters and digits
letters = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
digits = set("0123456789")
# Check if the intersection of the input string and the sets of letters an... |
Python program to check if a string has at least one letter and one number | https://www.geeksforgeeks.org/python-program-to-check-if-a-string-has-at-least-one-letter-and-one-number/ | checkString = lambda s: any(c.isalpha() for c in s) and any(c.isdigit() for c in s)
# driver code
print(checkString("thishasboth29"))
print(checkString("geeksforgeeks")) | Input: welcome2ourcountry34
Output: True | Python program to check if a string has at least one letter and one number
checkString = lambda s: any(c.isalpha() for c in s) and any(c.isdigit() for c in s)
# driver code
print(checkString("thishasboth29"))
print(checkString("geeksforgeeks"))
Input: welcome2ourcountry34
Output: True
[END] |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | # Python program to accept the strings
# which contains all the vowels
# Function for check if string
# is accepted or not
def check(string):
string = string.lower()
# set() function convert "aeiou"
# string into set of characters
# i.e.vowels = {'a', 'e', 'i', 'o', 'u'}
vowels = set("aeiou")
... | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
# Python program to accept the strings
# which contains all the vowels
# Function for check if string
# is accepted or not
def check(string):
string = string.lower()
# set() function convert "aeiou"
# string into set of characters
... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | def check(string):
string = string.replace(" ", "")
string = string.lower()
vowel = [
string.count("a"),
string.count("e"),
string.count("i"),
string.count("o"),
string.count("u"),
]
# If 0 is present int vowel count array
if vowel.count(0) > 0:
r... | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
def check(string):
string = string.replace(" ", "")
string = string.lower()
vowel = [
string.count("a"),
string.count("e"),
string.count("i"),
string.count("o"),
string.count("u"),
]
# If ... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | # Python program for the above approach
def check(string):
if len(set(string.lower()).intersection("aeiou")) >= 5:
return "accepted"
else:
return "not accepted"
# Driver code
if __name__ == "__main__":
string = "geeksforgeeks"
print(check(string)) | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
# Python program for the above approach
def check(string):
if len(set(string.lower()).intersection("aeiou")) >= 5:
return "accepted"
else:
return "not accepted"
# Driver code
if __name__ == "__main__":
string = "geeksfo... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | # import library
import re
sampleInput = "aeioAEiuioea"
# regular expression to find the strings
# which have characters other than a,e,i,o and u
c = re.compile("[^aeiouAEIOU]")
# use findall() to get the list of strings
# that have characters other than a,e,i,o and u.
if len(c.findall(sampleInput)):
print("Not ... | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
# import library
import re
sampleInput = "aeioAEiuioea"
# regular expression to find the strings
# which have characters other than a,e,i,o and u
c = re.compile("[^aeiouAEIOU]")
# use findall() to get the list of strings
# that have characters ot... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | # Python | Program to accept the strings which contains all vowels
def all_vowels(str_value):
new_list = [char for char in str_value.lower() if char in "aeiou"]
if new_list:
dic, lst = {}, []
for char in new_list:
dic["a"] = new_list.count("a")
dic["e"] = new_list.cou... | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
# Python | Program to accept the strings which contains all vowels
def all_vowels(str_value):
new_list = [char for char in str_value.lower() if char in "aeiou"]
if new_list:
dic, lst = {}, []
for char in new_list:
... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | # Python program to accept the strings
# which contains all the vowels
# Function for check if string
# is accepted or not
def check(string):
# Checking if "aeiou" is a subset of the set of all letters in the string
if set("aeiou").issubset(set(string.lower())):
return "Accepted"
return "Not accep... | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
# Python program to accept the strings
# which contains all the vowels
# Function for check if string
# is accepted or not
def check(string):
# Checking if "aeiou" is a subset of the set of all letters in the string
if set("aeiou").issubse... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | import collections
def check(string):
# create a Counter object to count the occurrences of each character
counter = collections.Counter(string.lower())
# set of vowels
vowels = set("aeiou")
# counter for the number of vowels present
vowel_count = 0
# check if each vowel is present in t... | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
import collections
def check(string):
# create a Counter object to count the occurrences of each character
counter = collections.Counter(string.lower())
# set of vowels
vowels = set("aeiou")
# counter for the number of vowels... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | # Python program to accept the strings
# which contains all the vowels
# Function for check if string
# is accepted or not
# using all() method
def check(string):
vowels = "aeiou" # storing vowels
if all(vowel in string.lower() for vowel in vowels):
return "Accepted"
return "Not accepted"
# i... | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
# Python program to accept the strings
# which contains all the vowels
# Function for check if string
# is accepted or not
# using all() method
def check(string):
vowels = "aeiou" # storing vowels
if all(vowel in string.lower() for vowe... |
Python | Program to accept the strings which contains all vowelsvowels | https://www.geeksforgeeks.org/python-program-to-accept-the-strings-which-contains-all-vowels/ | # function definition
def check(s):
A = {"a", "e", "i", "o", "u"}
# using the set difference
if len(A.difference(set(s.lower()))) == 0:
print("accepted")
else:
print("not accepted")
# input
s = "SEEquoiaL"
# function call
check(s) | #Input : geeksforgeeks
#Output : Not Accepted | Python | Program to accept the strings which contains all vowelsvowels
# function definition
def check(s):
A = {"a", "e", "i", "o", "u"}
# using the set difference
if len(A.difference(set(s.lower()))) == 0:
print("accepted")
else:
print("not accepted")
# input
s = "SEEquoiaL"
# functio... |
Python | Count the Number of matching characters in a pair of string | https://www.geeksforgeeks.org/python-count-the-number-of-matching-characters-in-a-pair-of-string/ | // C++ code to count number of matching// characters in a pair of strings??????# include <bits/stdc++.h>using namespace std??????// Function to count the matching charactersvoid count(string str1, string str2){????????????????????????int c = 0, j = 0??????????????????????????????// Traverse the string 1 char by char???... | #Input : str1 = 'abcdef'
str2 = 'defghia' | Python | Count the Number of matching characters in a pair of string
// C++ code to count number of matching// characters in a pair of strings??????# include <bits/stdc++.h>using namespace std??????// Function to count the matching charactersvoid count(string str1, string str2){????????????????????????int c = 0, j = 0?... |
Python | Count the Number of matching characters in a pair of string | https://www.geeksforgeeks.org/python-count-the-number-of-matching-characters-in-a-pair-of-string/ | # Python code to count number of unique matching
# characters in a pair of strings
# count function count the common unique
# characters present in both strings .
def count(str1, str2):
# set of characters of string1
set_string1 = set(str1)
# set of characters of string2
set_string2 = set(str2)
... | #Input : str1 = 'abcdef'
str2 = 'defghia' | Python | Count the Number of matching characters in a pair of string
# Python code to count number of unique matching
# characters in a pair of strings
# count function count the common unique
# characters present in both strings .
def count(str1, str2):
# set of characters of string1
set_string1 = set(str1)
... |
Python | Count the Number of matching characters in a pair of string | https://www.geeksforgeeks.org/python-count-the-number-of-matching-characters-in-a-pair-of-string/ | def count(str1, str2):
# Initialize an empty dictionary to keep track of the count of each character in str1.
char_count = {}
# Iterate over each character in str1.
for char in str1:
# If the character is already in the dictionary, increment its count.
if char in char_count:
... | #Input : str1 = 'abcdef'
str2 = 'defghia' | Python | Count the Number of matching characters in a pair of string
def count(str1, str2):
# Initialize an empty dictionary to keep track of the count of each character in str1.
char_count = {}
# Iterate over each character in str1.
for char in str1:
# If the character is already in the dictio... |
Python program to count number of vowels using sets in given string | https://www.geeksforgeeks.org/python-program-count-number-vowels-using-sets-given-string/ | # Python3 code to count vowel in
# a string using set
# Function to count vowel
def vowel_count(str):
# Initializing 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 ... | #Input : GeeksforGeeks
#Output : No. of vowels : 5 | Python program to count number of vowels using sets in given string
# Python3 code to count vowel in
# a string using set
# Function to count vowel
def vowel_count(str):
# Initializing count variable to 0
count = 0
# Creating a set of vowels
vowel = set("aeiouAEIOU")
# Loop to traverse the alpha... |
Python program to count number of vowels using sets in given string | https://www.geeksforgeeks.org/python-program-count-number-vowels-using-sets-given-string/ | def vowel_count(str):
# Creating a list of vowels
vowels = "aeiouAEIOU"
# Using list comprehension to count the number of vowels in the string
count = len([char for char in str if char in vowels])
# Printing the count of vowels in the string
print("No. of vowels :", count)
# Driver code
str ... | #Input : GeeksforGeeks
#Output : No. of vowels : 5 | Python program to count number of vowels using sets in given string
def vowel_count(str):
# Creating a list of vowels
vowels = "aeiouAEIOU"
# Using list comprehension to count the number of vowels in the string
count = len([char for char in str if char in vowels])
# Printing the count of vowels in... |
Python Program to remove all duplicates from a given string | https://www.geeksforgeeks.org/remove-duplicates-given-string-python/ | from collections import OrderedDict
# Function to remove all duplicates from string
# and order does not matter
def removeDupWithoutOrder(str):
# set() --> A Set is an unordered collection
# data type that is iterable, mutable,
# and has no duplicate elements.
# "".join() --> It joins ... |
#Output : Without Order = foskerg | Python Program to remove all duplicates from a given string
from collections import OrderedDict
# Function to remove all duplicates from string
# and order does not matter
def removeDupWithoutOrder(str):
# set() --> A Set is an unordered collection
# data type that is iterable, mutable,
# ... |
Python Program to remove all duplicates from a given string | https://www.geeksforgeeks.org/remove-duplicates-given-string-python/ | def removeDuplicate(str):
s = set(str)
s = "".join(s)
print("Without Order:", s)
t = ""
for i in str:
if i in t:
pass
else:
t = t + i
print("With Order:", t)
str = "geeksforgeeks"
removeDuplicate(str) |
#Output : Without Order = foskerg | Python Program to remove all duplicates from a given string
def removeDuplicate(str):
s = set(str)
s = "".join(s)
print("Without Order:", s)
t = ""
for i in str:
if i in t:
pass
else:
t = t + i
print("With Order:", t)
str = "geeksforgeeks"
removeDupl... |
Python Program to remove all duplicates from a given string | https://www.geeksforgeeks.org/remove-duplicates-given-string-python/ | from collections import OrderedDict
ordinary_dictionary = {}
ordinary_dictionary["a"] = 1
ordinary_dictionary["b"] = 2
ordinary_dictionary["c"] = 3
ordinary_dictionary["d"] = 4
ordinary_dictionary["e"] = 5
# Output = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}
print(ordinary_dictionary)
ordered_dictionary = OrderedDict... |
#Output : Without Order = foskerg | Python Program to remove all duplicates from a given string
from collections import OrderedDict
ordinary_dictionary = {}
ordinary_dictionary["a"] = 1
ordinary_dictionary["b"] = 2
ordinary_dictionary["c"] = 3
ordinary_dictionary["d"] = 4
ordinary_dictionary["e"] = 5
# Output = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}
... |
Python Program to remove all duplicates from a given string | https://www.geeksforgeeks.org/remove-duplicates-given-string-python/ | from collections import OrderedDict
seq = ("name", "age", "gender")
dict = OrderedDict.fromkeys(seq)
# Output = {'age': None, 'name': None, 'gender': None}
print(str(dict))
dict = OrderedDict.fromkeys(seq, 10)
# Output = {'age': 10, 'name': 10, 'gender': 10}
print(str(dict)) |
#Output : Without Order = foskerg | Python Program to remove all duplicates from a given string
from collections import OrderedDict
seq = ("name", "age", "gender")
dict = OrderedDict.fromkeys(seq)
# Output = {'age': None, 'name': None, 'gender': None}
print(str(dict))
dict = OrderedDict.fromkeys(seq, 10)
# Output = {'age': 10, 'name': 10, 'gender': 10... |
Python Program to remove all duplicates from a given string | https://www.geeksforgeeks.org/remove-duplicates-given-string-python/ | import operator as op
def removeDuplicate(str):
s = set(str)
s = "".join(s)
print("Without Order:", s)
t = ""
for i in str:
if op.countOf(t, i) > 0:
pass
else:
t = t + i
print("With Order:", t)
str = "geeksforgeeks"
removeDuplicate(str) |
#Output : Without Order = foskerg | Python Program to remove all duplicates from a given string
import operator as op
def removeDuplicate(str):
s = set(str)
s = "".join(s)
print("Without Order:", s)
t = ""
for i in str:
if op.countOf(t, i) > 0:
pass
else:
t = t + i
print("With Order:",... |
Python - Least Frequent Character in String | https://www.geeksforgeeks.org/python-least-frequent-character-in-string/?ref=leftbar-rightbar | # Python 3 code to demonstrate
# Least Frequent Character in String
# naive method
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using naive method to get
# Least Frequent Character in String
all_freq = {}
for i in test_str:
if i in al... |
#Output : The original string is : GeeksforGeeks | Python - Least Frequent Character in String
# Python 3 code to demonstrate
# Least Frequent Character in String
# naive method
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using naive method to get
# Least Frequent Character in String
a... |
Python - Least Frequent Character in String | https://www.geeksforgeeks.org/python-least-frequent-character-in-string/?ref=leftbar-rightbar | # Python 3 code to demonstrate
# Least Frequent Character in String
# collections.Counter() + min()
from collections import Counter
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using collections.Counter() + min() to get
# Least Frequent C... |
#Output : The original string is : GeeksforGeeks | Python - Least Frequent Character in String
# Python 3 code to demonstrate
# Least Frequent Character in String
# collections.Counter() + min()
from collections import Counter
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using collectio... |
Python - Least Frequent Character in String | https://www.geeksforgeeks.org/python-least-frequent-character-in-string/?ref=leftbar-rightbar | from collections import defaultdict
def least_frequent_char(string):
freq = defaultdict(int)
for char in string:
freq[char] += 1
min_freq = min(freq.values())
least_frequent_chars = [char for char in freq if freq[char] == min_freq]
return "".join(sorted(least_frequent_chars))[0]
# Exampl... |
#Output : The original string is : GeeksforGeeks | Python - Least Frequent Character in String
from collections import defaultdict
def least_frequent_char(string):
freq = defaultdict(int)
for char in string:
freq[char] += 1
min_freq = min(freq.values())
least_frequent_chars = [char for char in freq if freq[char] == min_freq]
return "".jo... |
Python - Least Frequent Character in String | https://www.geeksforgeeks.org/python-least-frequent-character-in-string/?ref=leftbar-rightbar | import numpy as np
def least_frequent_char(string):
freq = {char: string.count(char) for char in set(string)}
return list(freq.keys())[np.argmin(list(freq.values()))]
# Example usage
input_string = "GeeksforGeeks"
min_char = least_frequent_char(input_string)
print("The original string is:", input_string)
pr... |
#Output : The original string is : GeeksforGeeks | Python - Least Frequent Character in String
import numpy as np
def least_frequent_char(string):
freq = {char: string.count(char) for char in set(string)}
return list(freq.keys())[np.argmin(list(freq.values()))]
# Example usage
input_string = "GeeksforGeeks"
min_char = least_frequent_char(input_string)
pri... |
Python - Least Frequent Character in String | https://www.geeksforgeeks.org/python-least-frequent-character-in-string/?ref=leftbar-rightbar | # Python program for the above approach
# Function to find the least frequent characters
def least_frequent_char(input_str):
freq_dict = {}
for char in input_str:
freq_dict[char] = freq_dict.get(char, 0) + 1
min_value = min(freq_dict.values())
least_frequent_char = ""
# Traversing the d... |
#Output : The original string is : GeeksforGeeks | Python - Least Frequent Character in String
# Python program for the above approach
# Function to find the least frequent characters
def least_frequent_char(input_str):
freq_dict = {}
for char in input_str:
freq_dict[char] = freq_dict.get(char, 0) + 1
min_value = min(freq_dict.values())
le... |
Python | Maximum frequency character in String | https://www.geeksforgeeks.org/python-maximum-frequency-character-in-string/?ref=leftbar-rightbar | # Python 3 code to demonstrate
# Maximum frequency character in String
# naive method
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using naive method to get
# Maximum frequency character in String
all_freq = {}
for i in test_str:
if i... |
#Output : The original string is : GeeksforGeeks | Python | Maximum frequency character in String
# Python 3 code to demonstrate
# Maximum frequency character in String
# naive method
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using naive method to get
# Maximum frequency character in S... |
Python | Maximum frequency character in String | https://www.geeksforgeeks.org/python-maximum-frequency-character-in-string/?ref=leftbar-rightbar | # Python 3 code to demonstrate
# Maximum frequency character in String
# collections.Counter() + max()
from collections import Counter
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using collections.Counter() + max() to get
# Maximum frequ... |
#Output : The original string is : GeeksforGeeks | Python | Maximum frequency character in String
# Python 3 code to demonstrate
# Maximum frequency character in String
# collections.Counter() + max()
from collections import Counter
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# using colle... |
Python | Maximum frequency character in String | https://www.geeksforgeeks.org/python-maximum-frequency-character-in-string/?ref=leftbar-rightbar | # initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# creating an empty dictionary
freq = {}
# counting frequency of each character
for char in test_str:
if char in freq:
freq[char] += 1
else:
freq[char] = 1
# finding the ... |
#Output : The original string is : GeeksforGeeks | Python | Maximum frequency character in String
# initializing string
test_str = "GeeksforGeeks"
# printing original string
print("The original string is : " + test_str)
# creating an empty dictionary
freq = {}
# counting frequency of each character
for char in test_str:
if char in freq:
freq[char] += 1
... |
Python | Maximum frequency character in String | https://www.geeksforgeeks.org/python-maximum-frequency-character-in-string/?ref=leftbar-rightbar | test_str = "GeeksforGeeks"
res = max(test_str, key=lambda x: test_str.count(x))
print(res) |
#Output : The original string is : GeeksforGeeks | Python | Maximum frequency character in String
test_str = "GeeksforGeeks"
res = max(test_str, key=lambda x: test_str.count(x))
print(res)
#Output : The original string is : GeeksforGeeks
[END] |
Python - Odd Frequency Character | https://www.geeksforgeeks.org/python-odd-frequency-characters/?ref=leftbar-rightbar | # Python3 code to demonstrate working of
# Odd Frequency Characters
# Using list comprehension + defaultdict()
from collections import defaultdict
# helper_function
def hlper_fnc(test_str):
cntr = defaultdict(int)
for ele in test_str:
cntr[ele] += 1
return [val for val, chr in cntr.items() if chr ... | #Input : test_str = 'geekforgeeks'??????
#Output : ['r', 'o', 'f', 's | Python - Odd Frequency Character
# Python3 code to demonstrate working of
# Odd Frequency Characters
# Using list comprehension + defaultdict()
from collections import defaultdict
# helper_function
def hlper_fnc(test_str):
cntr = defaultdict(int)
for ele in test_str:
cntr[ele] += 1
return [val f... |
Python - Odd Frequency Character | https://www.geeksforgeeks.org/python-odd-frequency-characters/?ref=leftbar-rightbar | # Python3 code to demonstrate working of
# Odd Frequency Characters
# Using list comprehension + Counter()
from collections import Counter
# initializing string
test_str = "geekforgeeks is best for geeks"
# printing original string
print("The original string is : " + str(test_str))
# Odd Frequency Characters
# Usin... | #Input : test_str = 'geekforgeeks'??????
#Output : ['r', 'o', 'f', 's | Python - Odd Frequency Character
# Python3 code to demonstrate working of
# Odd Frequency Characters
# Using list comprehension + Counter()
from collections import Counter
# initializing string
test_str = "geekforgeeks is best for geeks"
# printing original string
print("The original string is : " + str(test_str))... |
Python - Odd Frequency Character | https://www.geeksforgeeks.org/python-odd-frequency-characters/?ref=leftbar-rightbar | # Python3 code to demonstrate working of
# Odd Frequency Characters
# initializing string
test_str = "geekforgeeks is best for geeks"
# printing original string
print("The original string is : " + str(test_str))
# Odd Frequency Characters
x = set(test_str)
res = []
for i in x:
if test_str.count(i) % 2 != 0:
... | #Input : test_str = 'geekforgeeks'??????
#Output : ['r', 'o', 'f', 's | Python - Odd Frequency Character
# Python3 code to demonstrate working of
# Odd Frequency Characters
# initializing string
test_str = "geekforgeeks is best for geeks"
# printing original string
print("The original string is : " + str(test_str))
# Odd Frequency Characters
x = set(test_str)
res = []
for i in x:
... |
Python - Odd Frequency Character | https://www.geeksforgeeks.org/python-odd-frequency-characters/?ref=leftbar-rightbar | # Python3 code to demonstrate working of
# Odd Frequency Characters
import operator as op
# initializing string
test_str = "geekforgeeks is best for geeks"
# printing original string
print("The original string is : " + str(test_str))
# Odd Frequency Characters
x = set(test_str)
res = []
for i in x:
if op.countOf... | #Input : test_str = 'geekforgeeks'??????
#Output : ['r', 'o', 'f', 's | Python - Odd Frequency Character
# Python3 code to demonstrate working of
# Odd Frequency Characters
import operator as op
# initializing string
test_str = "geekforgeeks is best for geeks"
# printing original string
print("The original string is : " + str(test_str))
# Odd Frequency Characters
x = set(test_str)
res... |
Python - Odd Frequency Character | https://www.geeksforgeeks.org/python-odd-frequency-characters/?ref=leftbar-rightbar | def odd_freq_chars(test_str):
# Create an empty dictionary to hold character counts
char_counts = {}
# Loop through each character in the input string
for char in test_str:
# Increment the count for this character in the dictionary
# using the get() method to safely handle uninitialized... | #Input : test_str = 'geekforgeeks'??????
#Output : ['r', 'o', 'f', 's | Python - Odd Frequency Character
def odd_freq_chars(test_str):
# Create an empty dictionary to hold character counts
char_counts = {}
# Loop through each character in the input string
for char in test_str:
# Increment the count for this character in the dictionary
# using the get() me... |
Python - Odd Frequency Character | https://www.geeksforgeeks.org/python-odd-frequency-characters/?ref=leftbar-rightbar | # Python3 code to demonstrate working of# Odd Frequency Characters??????from collections import defaultdict, Counter??????# initializing stringtest_str = 'geekforgeeks is best for geeks'??????# printing original "The original string is : " + str(test_str))??????# Odd Frequency Characters using defaultdictchar_count = d... | #Input : test_str = 'geekforgeeks'??????
#Output : ['r', 'o', 'f', 's | Python - Odd Frequency Character
# Python3 code to demonstrate working of# Odd Frequency Characters??????from collections import defaultdict, Counter??????# initializing stringtest_str = 'geekforgeeks is best for geeks'??????# printing original "The original string is : " + str(test_str))??????# Odd Frequency Charact... |
Python - Specific Characters Frequency in String List | https://www.geeksforgeeks.org/python-specific-characters-frequency-in-string-list/ | # Python3 code to demonstrate working of
# Specific Characters Frequency in String List
# Using join() + Counter()
from collections import Counter
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original list : " + str(test_list))
# char list
chr_list = ["e", ... |
#Output : The original list : ['geeksforgeeks is best for geeks'] | Python - Specific Characters Frequency in String List
# Python3 code to demonstrate working of
# Specific Characters Frequency in String List
# Using join() + Counter()
from collections import Counter
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original l... |
Python - Specific Characters Frequency in String List | https://www.geeksforgeeks.org/python-specific-characters-frequency-in-string-list/ | # Python3 code to demonstrate working of
# Specific Characters Frequency in String List
# Using chain.from_iterable() + Counter() + dictionary comprehension
from collections import Counter
from itertools import chain
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("... |
#Output : The original list : ['geeksforgeeks is best for geeks'] | Python - Specific Characters Frequency in String List
# Python3 code to demonstrate working of
# Specific Characters Frequency in String List
# Using chain.from_iterable() + Counter() + dictionary comprehension
from collections import Counter
from itertools import chain
# initializing lists
test_list = ["geeksforgee... |
Python - Specific Characters Frequency in String List | https://www.geeksforgeeks.org/python-specific-characters-frequency-in-string-list/ | # Python3 code to demonstrate working of
# Specific Characters Frequency in String List
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original list : " + str(test_list))
# char list
chr_list = ["e", "b", "g"]
d = dict()
for i in chr_list:
d[i] = test_li... |
#Output : The original list : ['geeksforgeeks is best for geeks'] | Python - Specific Characters Frequency in String List
# Python3 code to demonstrate working of
# Specific Characters Frequency in String List
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original list : " + str(test_list))
# char list
chr_list = ["e", "b"... |
Python - Specific Characters Frequency in String List | https://www.geeksforgeeks.org/python-specific-characters-frequency-in-string-list/ | # Python3 code to demonstrate working of
# Specific Characters Frequency in String List
import operator as op
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original list : " + str(test_list))
# char list
chr_list = ["e", "b", "g"]
d = dict()
for i in chr_li... |
#Output : The original list : ['geeksforgeeks is best for geeks'] | Python - Specific Characters Frequency in String List
# Python3 code to demonstrate working of
# Specific Characters Frequency in String List
import operator as op
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original list : " + str(test_list))
# char lis... |
Python - Specific Characters Frequency in String List | https://www.geeksforgeeks.org/python-specific-characters-frequency-in-string-list/ | # initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original list : " + str(test_list))
# char list
chr_list = ["e", "b", "g"]
# initializing dictionary for result
res = {}
# loop through each character in the test_list and count their frequency
for char in "".jo... |
#Output : The original list : ['geeksforgeeks is best for geeks'] | Python - Specific Characters Frequency in String List
# initializing lists
test_list = ["geeksforgeeks is best for geeks"]
# printing original list
print("The original list : " + str(test_list))
# char list
chr_list = ["e", "b", "g"]
# initializing dictionary for result
res = {}
# loop through each character in t... |
Python | Frequency of numbers in String | https://www.geeksforgeeks.org/python-frequency-of-numbers-in-string/ | # Python3 code to demonstrate working of
# Frequency of numbers in String
# Using re.findall() + len()
import re
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
# Using re.findall() + len()
res =... |
#Output : The original string is : geeks4feeks is No. 1 4 geeks | Python | Frequency of numbers in String
# Python3 code to demonstrate working of
# Frequency of numbers in String
# Using re.findall() + len()
import re
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in S... |
Python | Frequency of numbers in String | https://www.geeksforgeeks.org/python-frequency-of-numbers-in-string/ | # Python3 code to demonstrate working of
# Frequency of numbers in String
# Using re.findall() + sum()
import re
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
# Using re.findall() + sum()
res =... |
#Output : The original string is : geeks4feeks is No. 1 4 geeks | Python | Frequency of numbers in String
# Python3 code to demonstrate working of
# Frequency of numbers in String
# Using re.findall() + sum()
import re
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in S... |
Python | Frequency of numbers in String | https://www.geeksforgeeks.org/python-frequency-of-numbers-in-string/ | # Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = 0
for i in test_str:
if i.isdigit():
res += 1
# printin... |
#Output : The original string is : geeks4feeks is No. 1 4 geeks | Python | Frequency of numbers in String
# Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = 0
for i in test_str:
if... |
Python | Frequency of numbers in String | https://www.geeksforgeeks.org/python-frequency-of-numbers-in-string/ | # Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = 0
digits = "0123456789"
for i in test_str:
if i in digits:
... |
#Output : The original string is : geeks4feeks is No. 1 4 geeks | Python | Frequency of numbers in String
# Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = 0
digits = "0123456789"
for... |
Python | Frequency of numbers in String | https://www.geeksforgeeks.org/python-frequency-of-numbers-in-string/ | # Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = len(list(filter(lambda x: x.isdigit(), test_str)))
# printing resu... |
#Output : The original string is : geeks4feeks is No. 1 4 geeks | Python | Frequency of numbers in String
# Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = len(list(filter(lambda x: x... |
Python | Frequency of numbers in String | https://www.geeksforgeeks.org/python-frequency-of-numbers-in-string/ | # Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = sum(map(str.isdigit, test_str))
# printing result
print("Count of ... |
#Output : The original string is : geeks4feeks is No. 1 4 geeks | Python | Frequency of numbers in String
# Python3 code to demonstrate working of
# Frequency of numbers in String
# initializing string
test_str = "geeks4feeks is No. 1 4 geeks"
# printing original string
print("The original string is : " + test_str)
# Frequency of numbers in String
res = sum(map(str.isdigit, test_s... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | // C++ program to check if a string// contains any special character??????// import required packages#include <iostream>#include <regex>using namespace std;??????// Function checks if the string// contains any special charactervoid run(string str){??????????????????????????????????????????????????????"[@_!#$%^&*()<>?/|... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
// C++ program to check if a string// contains any special character??????// import required packages#include <iostream>#include <regex>using namespace std;??????// Function checks if the string// contains any special charactervoid run(string str){???... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | # Python3 program to check if a string
# contains any special character
# import required package
import re
# Function checks if the string
# contains any special character
def run(string):
# Make own character set and pass
# this as argument in compile method
regex = re.compile("[@_!#$%^&*()<>?/\|}{~:]"... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
# Python3 program to check if a string
# contains any special character
# import required package
import re
# Function checks if the string
# contains any special character
def run(string):
# Make own character set and pass
# this as argume... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | <?Php// PHP program to check if a string// contains any special character??????// Function checks if the string// contains any special characterfunction run($string){????????????????????????$regex = preg_match('[@_!#$%^&*()<>?/\|}{~:]',????????????????????????????????????????????????????????????????????????????????????... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
<?Php// PHP program to check if a string// contains any special character??????// Function checks if the string// contains any special characterfunction run($string){????????????????????????$regex = preg_match('[@_!#$%^&*()<>?/\|}{~:]',???????????????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | import java.util.regex.Matcher;import java.util.regex.Pattern;??????public class Main {????????????????????????public static void main(String[] args)??????????????????"Geeks$For$Geeks";????????????????????????????????????????????????Pattern pattern??????????"[@_!#$%^&*()<>?/|}{~:]");????????????????????????????????????... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
import java.util.regex.Matcher;import java.util.regex.Pattern;??????public class Main {????????????????????????public static void main(String[] args)??????????????????"Geeks$For$Geeks";????????????????????????????????????????????????Pattern pattern???... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | // C# program to check if a string// contains any special character??????using System;using System.Text.RegularExpressions;??????class Program {????????????????????????// Function checks if the string????????????????????????// contains any special character????????????????????????static void Run(string str)????????????... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
// C# program to check if a string// contains any special character??????using System;using System.Text.RegularExpressions;??????class Program {????????????????????????// Function checks if the string????????????????????????// contains any special cha... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | function hasSpecialChar(str) {????????????let regex = /[@!#$%^&*()_+\-=\"\\|,.<>\/?]/;????????????return regex.test(str);}????"Geeks$For$Geeks";if (!hasSpecialChar(str)) {????????????cons"String is accepted");} else {????????????cons"String is not accepted");} | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
function hasSpecialChar(str) {????????????let regex = /[@!#$%^&*()_+\-=\"\\|,.<>\/?]/;????????????return regex.test(str);}????"Geeks$For$Geeks";if (!hasSpecialChar(str)) {????????????cons"String is accepted");} else {????????????cons"String is not acc... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | // C++ code// to check if any special character is present// in a given string or not#include <iostream>#include <string>using namespace std;??????int main(){??????????????????????????????// Input s"Geeks$For$Geeks";????????????????????????int c = 0;??????????????????"[@_!#$%^&*()<>?}{~:]"; // special character set????... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
// C++ code// to check if any special character is present// in a given string or not#include <iostream>#include <string>using namespace std;??????int main(){??????????????????????????????// Input s"Geeks$For$Geeks";????????????????????????int c = 0;?... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | // Java code to check if any special character is present// in a given string or notimport java.util.*;class Main {????????????????????????public static void main(String[] args)????????????????????????{??????????????????????????"Geeks$For$Geeks";????????????????????????????????????????????????int c"[@_!#$%^&*()<>?}{~:]... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
// Java code to check if any special character is present// in a given string or notimport java.util.*;class Main {????????????????????????public static void main(String[] args)????????????????????????{??????????????????????????"Geeks$For$Geeks";?????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | # Python code
# to check if any special character is present
# in a given string or not
# input string
n = "Geeks$For$Geeks"
n.split()
c = 0
s = "[@_!#$%^&*()<>?/\|}{~:]" # special character set
for i in range(len(n)):
# checking if any special character is present in given string or not
if n[i] in s:
... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
# Python code
# to check if any special character is present
# in a given string or not
# input string
n = "Geeks$For$Geeks"
n.split()
c = 0
s = "[@_!#$%^&*()<>?/\|}{~:]" # special character set
for i in range(len(n)):
# checking if any special ... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | // JavaScript code// to check if any special character is present// in a given string or notconst n = "Geeks$For$Geeks";let c = 0;const s = "[@_!#$%^&*()<>?}{~:]"; // special character set??????for (let i = 0; i < n.length; i++) {????????????????????????// checking if any special character is present in given string or... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
// JavaScript code// to check if any special character is present// in a given string or notconst n = "Geeks$For$Geeks";let c = 0;const s = "[@_!#$%^&*()<>?}{~:]"; // special character set??????for (let i = 0; i < n.length; i++) {?????????????????????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | using System;??????class Program {????????????????????????static void Main(string[] args)????????????????????????{??????????????????????"Geeks$For$Geeks";????????????????????????????????????????????????int c"[@_!#$%^&*()<>?}{~:]"; // special???????????????????????????????????????????????????????????????????????????????... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
using System;??????class Program {????????????????????????static void Main(string[] args)????????????????????????{??????????????????????"Geeks$For$Geeks";????????????????????????????????????????????????int c"[@_!#$%^&*()<>?}{~:]"; // special??????????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | #include <iostream>#include <string>??????using namespace std;??????bool hasSpecialChar(string s){????????????????????????for (char c : s) {????????????????????????????????????????????????if (!(isalpha(c) || isdigit(c) || c == ' ')) {????????????????????????????????????????????????????????????"Hello World";????????????... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
#include <iostream>#include <string>??????using namespace std;??????bool hasSpecialChar(string s){????????????????????????for (char c : s) {????????????????????????????????????????????????if (!(isalpha(c) || isdigit(c) || c == ' ')) {?????????????????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | class Main {????????????????????????public static boolean hasSpecialChar(String s)????????????????????????{????????????????????????????????????????????????for (int i = 0; i < s.length(); i++) {????????????????????????????????????????????????????????????????????????char c = s.charAt(i);??????????????????????????????????... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
class Main {????????????????????????public static boolean hasSpecialChar(String s)????????????????????????{????????????????????????????????????????????????for (int i = 0; i < s.length(); i++) {??????????????????????????????????????????????????????????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | def has_special_char(s):
for c in s:
if not (c.isalpha() or c.isdigit() or c == " "):
return True
return False
# Test the function
s = "Hello World"
if has_special_char(s):
print("The string contains special characters.")
else:
print("The string does not contain special characters.... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
def has_special_char(s):
for c in s:
if not (c.isalpha() or c.isdigit() or c == " "):
return True
return False
# Test the function
s = "Hello World"
if has_special_char(s):
print("The string contains special character... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | using System;??????class GFG {????????????????????????// This method checks if a string contains any special????????????????????????// characters.????????????????????????public static bool HasSpecialChar(string s)????????????????????????{????????????????????????????????????????????????// Iterate over each character in ... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
using System;??????class GFG {????????????????????????// This method checks if a string contains any special????????????????????????// characters.????????????????????????public static bool HasSpecialChar(string s)????????????????????????{?????????????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | function hasSpecialChar(s) {????????????????????????for (let i = 0; i < s.length; i++) {????????????????????????????????????????????????const c = s.charAt(i);????????????????????????????????????????????????if (!(c.match(/^[a-zA-Z0-9 ]+$/))) {??????????????"Hello World";if (hasSpecialChar(s)) {????????????????????"The s... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
function hasSpecialChar(s) {????????????????????????for (let i = 0; i < s.length; i++) {????????????????????????????????????????????????const c = s.charAt(i);????????????????????????????????????????????????if (!(c.match(/^[a-zA-Z0-9 ]+$/))) {?????????... |
Python | Program to check if a string contains any special character | https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/ | import string
def check_string(s):
for c in s:
if c in string.punctuation:
print("String is not accepted")
return
print("String is accepted")
# Example usage
check_string("Geeks$For$Geeks") # Output: String is not accepted
check_string("Geeks For Geeks") # Output: String is... | #Input : Geeks$For$Geeks
#Output : String is not accepted. | Python | Program to check if a string contains any special character
import string
def check_string(s):
for c in s:
if c in string.punctuation:
print("String is not accepted")
return
print("String is accepted")
# Example usage
check_string("Geeks$For$Geeks") # Output: String... |
Generating random strings until a given string is generated | https://www.geeksforgeeks.org/python-program-match-string-random-strings-length/ | # Python program to generate and match??????# the string from all random strings# of same length????????????# Importing string, random# and time modulesimport stringimport randomimport time????????????# all possible characters including??????# lowercase, uppercase and special symbolspossibleCharacters = string.ascii_lo... | #Input : GFG
| Generating random strings until a given string is generated
# Python program to generate and match??????# the string from all random strings# of same length????????????# Importing string, random# and time modulesimport stringimport randomimport time????????????# all possible characters including??????# lowercase, upper... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | // C++ program to find all string// which are greater than given length k??????#include <bits/stdc++.h>using namespace std;??????// function find string greater than// length kvoid string_k(string s, int k){????????????????????????// create an empty s"";????????????????????????// iterate the loop till every space??????... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
// C++ program to find all string// which are greater than given length k??????#include <bits/stdc++.h>using namespace std;??????// function find string greater than// length kvoid string_k(string s, int k){????????????????????????// create an empty s"";??????????... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | // C# program to find all string// which are greater than given length k??????using System;??????class GFG {??????????????????????????????// function find string greater than????????????????????????// length k????????????????????????static void string_k(string s, int k)??????????????????"";?????????????????????????????... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
// C# program to find all string// which are greater than given length k??????using System;??????class GFG {??????????????????????????????// function find string greater than????????????????????????// length k????????????????????????static void string_k(string s, ... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | // Java program to find all string// which are greater than given length k??????import java.io.*;import java.util.*;??????public class GFG {??????????????????????????????// function find string greater than????????????????????????// length k????????????????????????static void string_k(String s, int k)??????????????????... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
// Java program to find all string// which are greater than given length k??????import java.io.*;import java.util.*;??????public class GFG {??????????????????????????????// function find string greater than????????????????????????// length k???????????????????????... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | # Python program to find all string
# which are greater than given length k
# function find string greater than length k
def string_k(k, str):
# create the empty string
string = []
# split the string where space is comes
text = str.split(" ")
# iterate the loop till every substring
for x in... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
# Python program to find all string
# which are greater than given length k
# function find string greater than length k
def string_k(k, str):
# create the empty string
string = []
# split the string where space is comes
text = str.split(" ")
... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | <?php// PHP program to find all $// which are greater than given length k??????// function find string greater than// length kfunction string_k($s, $k){?????????????????????????????????????????????????????"";??????????????????????????????????????????????????????// iterate the loop till every space??????????????????????... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
<?php// PHP program to find all $// which are greater than given length k??????// function find string greater than// length kfunction string_k($s, $k){?????????????????????????????????????????????????????"";??????????????????????????????????????????????????????//... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | <script>// javascript program to find all string// which are greater than given length k??????????????????????????????// function find string greater than????????????????????????// length k????????????????????????function string_k( s , k) {??????????????"";??????????????????????????????????????????????????????// iterat... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
<script>// javascript program to find all string// which are greater than given length k??????????????????????????????// function find string greater than????????????????????????// length k????????????????????????function string_k( s , k) {??????????????"";???????... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | #include <iostream>#include <sstream>#include <string>#include <vector>??????using namespace std;??????int main(){??????????????????"hello geeks for geeks is computer "????????????????????????????????????????????"science portal";????????????????????????int length = 4;????????????????????????vector<string> words;???????... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
#include <iostream>#include <sstream>#include <string>#include <vector>??????using namespace std;??????int main(){??????????????????"hello geeks for geeks is computer "????????????????????????????????????????????"science portal";????????????????????????int length ... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | using System;using System.Linq;??????class Program{????????????????????????static void Main(string[] args)???????????????????????"hello geeks for geeks is computer science portal";????????????????????????????????????????????????int length = 4;????????????????????????????????????????????????var words = sentence.Split(' ... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
using System;using System.Linq;??????class Program{????????????????????????static void Main(string[] args)???????????????????????"hello geeks for geeks is computer science portal";????????????????????????????????????????????????int length = 4;?????????????????????... |
Find words which are greater than K than given length k | https://www.geeksforgeeks.org/find-words-greater-given-length-k/ | import java.util.Arrays;??????public class Main {????????????????????????public static void main(String[] args)????????????????????????{?????????????????????"hello geeks for geeks is computer science portal";????????????????????????????????????????????????int length = 4;????????????????????????????????????????????????S... | #Input : str = "hello geeks for geeks
is computer science portal" | Find words which are greater than K than given length k
import java.util.Arrays;??????public class Main {????????????????????????public static void main(String[] args)????????????????????????{?????????????????????"hello geeks for geeks is computer science portal";????????????????????????????????????????????????int leng... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.