0% found this document useful (0 votes)
18 views3 pages

CIS Assignment 6

Uploaded by

sniperlord2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

CIS Assignment 6

Uploaded by

sniperlord2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#1:

class ListNode:
def __init__(self, value=0, next_node=None):
self.value = value
self.next = next_node

def findNode(head):
slow = fast = head
for i in range(4):
if fast is None:
return None
fast = fast.next
while fast.next is not None:
fast = fast.next
slow = slow.next
return slow.value

elements = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]


head = ListNode(elements[0])
current = head
for value in elements[1:]:
current.next = ListNode(value)
current = current.next

fourth_from_end = findNode(head)
if fourth_from_end is not None:
print("Value of node:", findNode())
else:
print("Error")
#2:
class ListNode:
def __init__(self, value=0, next_node=None):
self.value = value
self.next = next_node

def reversedList(head):
prev = None
current = head

while current is not None:


next_node = current.next
current.next = prev
prev = current
current = next_node
return prev

# Reversing the linked list


head = reversedList(head)
print("Reversed Linked List:")
current = head
while current is not None:
print(current.value, end=" ")
current = current.next

#3:
text = """
Located on a hill overlooking Lake Erie, our 75-acre campus is known as one of
the most beautiful in the region. Elements of English Gothic architecture are
carried throughout our Old Main, academic buildings and student residence
halls. Our wonderful location is something we cherish deeply.

Grounded in the ideals of service, hospitality and entrepreneurship that


inspired our founders, a Mercyhurst education encourages the development of
lifelong passions and engagement with the larger world. Inspired by our motto,
“Carpe Diem,” our faculty and students embrace innovation and leadership in
service, as they make a difference within our gates and around the world.
"""

# Removing punctuation and converting all words to lowercase


import string
translator = str.maketrans('', '', string.punctuation)
text = text.translate(translator)
text = text.lower()

# Splitting the text


words = text.split()

# Counting each word


word_freq = {}
for word in words:
word_freq[word] = word_freq.get(word, 0) + 1

# Finding the most used word


most_used_word = max(word_freq, key=word_freq.get)

# Printing the most used word along with the frequency of following words
following_words = ['the', 'service', 'world', 'leadership']
print(f"The most used word is '{most_used_word}' with a frequency of
{word_freq[most_used_word]}.")

print("Frequency of the following words:")


for word in following_words:
print(f"'{word}': {word_freq.get(word, 0)}")

You might also like