NPTEL Joy Of Computing Using Python Week 8 Programming Assignment 2025

This Article describes solutions to the NPTEL Joy Of Computing Using Python Week 8 Programming Assignment 2025. The Code passed all the public and private test cases. The link is provided below if you didn't complete the Week 7 programming assignment of the joy of computing.

Also Read: NPTEL Joy of Computing Using Python Week 7 Programming Assignment Answers

Upcoming answers are provided in Telegram faster

Join us on Telegram 👉 CLICK HERE  

NPTEL Joy Of Computing Using Python Week 8 Programming Assignment 2025


NPTEL Joy Of Computing Using Python Week 8 Programming Assignment 2025


In Week 8, the following topics are discussed:
  • Tuples
  • Lottery Simulation - Profit or loss
  • Image Processing - Enhance your Images
  • Anagrams
  • Facebook Sentiment Analysis
Last Date: 20-03-2025

Q1. Remove Strings from a List of Tuples

You are given a list of tuples, where each tuple contains a mix of integers and strings. Your task is to remove all string elements from each tuple while keeping the original structure of the list.
  • If a tuple becomes empty after removing strings, it should be represented as an empty tuple ().
  • The number of tuples in the output list must be the same as in the input list.
Input Format:
A list of tuples

Output Format:
A list of tuples with all string elements removed.

Example :
Input:
[('string', ‘hello’), (2, 225), (3, '111')]

Output:

[(), (2, 225), (3,)]

Program Code:

def remove_strings_from_tuples(lst):
    return [tuple(item for item in tup if not isinstance(item, str)) for tup in lst]

input_data = eval(input())
output_data = remove_strings_from_tuples(input_data)
print(output_data, end='') {codeBox}

Q2. Remove Anagram Duplicates and Sort

You are given a sequence of words. Two words are anagrams if they contain the same letters in a different order. Your task is to remove any word that is an anagram of an earlier word while keeping the first occurrence. Finally, print the remaining words in sorted order.

Input Format:
A single line containing space-separated words, where each word consists of lowercase letters only.

Output Format:
A single line containing the remaining words in sorted order, space-separated.

Example:
Input:

code doce ecod framer frame

Output:
code frame framer

Program Code:

def remove_anagram_duplicates_and_sort(words):
    seen = set()
    unique_words = []

    for word in words:
        sorted_word = ''.join(sorted(word))  
        if sorted_word not in seen:
            seen.add(sorted_word)
            unique_words.append(word)

    return ' '.join(sorted(unique_words))  

words = input().split()  
result = remove_anagram_duplicates_and_sort(words)
print(result, end='') {codeBox}

Q3. Multiply Adjacent Elements in a Tuple

In many data processing tasks, cumulative operations like summation or multiplication of adjacent elements are required. This problem focuses on adjacent element multiplication, where each pair of consecutive elements in a given tuple is multiplied to generate a new tuple. The input tuple can contain both positive and negative integers, and the goal is to compute a resultant tuple where each element is the product of two adjacent elements in the original tuple.

Input Format:
A tuple of integers T with n elements (n ≥ 2)

Output Format:
A new tuple R of size (n - 1) where each element R[i] is the product of T[i] and T[i+1].

Example:
Input:

(1, -5, 7, 8, -10)

Output:
(-5, -35, 56, -80)

Explanation:
  • 1 × (-5) = -5
  • (-5) × 7 = -35
  • 7 × 8 = 56
  • 8 × (-10) = -80
Program Code:

def multiply_adjacent_elements(T):
    return tuple(T[i] * T[i+1] for i in range(len(T) - 1))

T = eval(input())
R = multiply_adjacent_elements(T)
print(R, end='') {codeBox}

Conclusion:

Join us on Telegram 👉 CLICK HERE

One Comment Please !

Post a Comment (0)
Previous Post Next Post