This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
NewerOlder