Skip to content

Instantly share code, notes, and snippets.

class Node:
def __init__(self, data):
self.data = data
self.next = None
class Singlylinkedlist:
def __init__(self):
self.head = None
def push_first(self, new_element):
#Creating node class of the singly linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
class SinglyLinkedList:
def __init__(self):
self.head = None
self.tail = None
#taking input from the user
string = input("Enter the string : ")
#converting string into list of its characters
strList=list(string)
#sorting elements of list
sortedString=''.join(sorted(strList))
print("String Sorted in ascending order :", sortedString)
#taking input from the user
str1 = input('Enter a string: ')
result=""
#iterating the characters of string
for i in str1:
count = 0
#another loop inside loop
for j in str1:
if i == j:
count=count+1
str1 = input('Enter a string: ')
sum=0
for i in string:
#if character is a digit
if i.isdigit():
#taking sum of integral digits present in the string
sum=sum+int(i)
print("sum=",sum)
str1 = input('Enter a string: ')
#converting the characters of string into a set elements to remove dublicacy.
#use join() function to join all the remaining set elements together.
result="".join(dict.fromkeys(str1))
print(result)
#taking inputs from the user
str1 = input('Enter first string: ')
str2 = input('Enter second string: ')
#printing the output after using join() method
print("String after concatenation :","".join([str1, str2]))
#taking input from the user
str1 = input('Enter first string: ')
str2 = input('Enter second string: ')
#using string concatenation method ‘+’
str3 = str1 + str2
print("String after concatenation :",str3)
#taking two strings as the input from the user
str1 = input('Enter first string: ')
str2 = input('Enter second string: ')
#comparing two strings
if str1== str2:
print("The strings are the same")
else:
print("The strings are not same")
#taking input from the user
string = input("Enter a String : ")
result=''
#iterating the string
for i in string:
#if the character is an alphabet
if i.isalpha():
result += i
print("String after removing the spaces :",result)