This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added Counting occurrence of each word (Python) #276 Signed-off-by: Nazish Khan <nazish1771@gmail.com> * Added Counting occurrence of each word (Python) in proper folder * Added Reverse a doubly linked list (Python) #283 Signed-off-by: Nazish Khan <nazish1771@gmail.com> * Delete CountingOccurrenceOfEachWord.py * Delete ReverseDoublyLinkedList.py * Added Reverse a doubly linked list (Python) #283 Signed-off-by: Nazish Khan <nazish1771@gmail.com> * Added Modified Kaprekar Numbers (Python) #281 Signed-off-by: Nazish Khan <nazish1771@gmail.com>
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Programming/Python/CountingOccurrenceOfEachWord/CountingOccurrenceOfEachWord.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# Program to find the number of occurrence of each unique word in the sequence of occurrence of each word. | ||
|
||
from collections import Counter | ||
|
||
if __name__ == '__main__': | ||
n = int(input()) | ||
w = [] | ||
for i in range(n): | ||
x = input() | ||
w.append(x) | ||
c = Counter(w) | ||
l = len(c) | ||
print(l) | ||
v = c.values() | ||
for i in v: | ||
print(i, end=' ') |
36 changes: 36 additions & 0 deletions
36
Programming/Python/ModifiedKaprekarNumber/ModifiedKaprekarNumber.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/python3 | ||
|
||
# Program to find all the Kaprekar Numbers in the given range. | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
# Function to find the Kaprekar Numbers. | ||
def kaprekarNumbers(p, q): | ||
lst = [] | ||
for i in range(p, q+1): | ||
y = len(str(i)) | ||
sq = i**2 | ||
x = len(str(sq)) | ||
r = int(sq%(10**y)) | ||
l = int(sq/(10**y)) | ||
if r+l == i: | ||
lst.append(int(i)) | ||
if lst == []: | ||
print("INVALID RANGE") | ||
return | ||
lst.sort() | ||
for j in range(len(lst)): | ||
print(lst[j], end=' ') | ||
|
||
|
||
# Main funtion to take inputs | ||
if __name__ == '__main__': | ||
p = int(input()) | ||
|
||
q = int(input()) | ||
|
||
kaprekarNumbers(p, q) |
72 changes: 72 additions & 0 deletions
72
Programming/Python/ReverseDoublyLinkedList/ReverseDoublyLinkedList.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/python3 | ||
|
||
# Program to inplement reversal of a Doubly LinkedList. | ||
|
||
import math | ||
import os | ||
import random | ||
import re | ||
import sys | ||
|
||
class DoublyLinkedListNode: | ||
def __init__(self, node_data): | ||
self.data = node_data | ||
self.next = None | ||
self.prev = None | ||
|
||
class DoublyLinkedList: | ||
def __init__(self): | ||
self.head = None | ||
self.tail = None | ||
|
||
def insert_node(self, node_data): | ||
node = DoublyLinkedListNode(node_data) | ||
|
||
if not self.head: | ||
self.head = node | ||
else: | ||
self.tail.next = node | ||
node.prev = self.tail | ||
|
||
|
||
self.tail = node | ||
|
||
def print_doubly_linked_list(node, sep): | ||
while node: | ||
print(str(node.data), end=' ') | ||
node = node.next | ||
|
||
|
||
# DoublyLinkedListNode: | ||
# int data | ||
# DoublyLinkedListNode next | ||
# DoublyLinkedListNode prev | ||
|
||
def reverse(head): | ||
r = head | ||
p = None | ||
while r!=None: | ||
q = r.next | ||
r.next = p | ||
r.prev = q | ||
p = r | ||
r = q | ||
return p | ||
|
||
|
||
if __name__ == '__main__': | ||
t = int(input()) | ||
|
||
for t_itr in range(t): | ||
llist_count = int(input()) | ||
|
||
llist = DoublyLinkedList() | ||
|
||
for _ in range(llist_count): | ||
llist_item = int(input()) | ||
llist.insert_node(llist_item) | ||
|
||
llist1 = reverse(llist.head) | ||
|
||
print_doubly_linked_list(llist1, ' ') | ||
|