Docsity

a COMPREHENSIVE REVIEWER FOR PROGRAMMING, Translations of Computer science

Toggle sidebar
bg1
#task 1
#nums = [1, 2, 2, 3, 4, 4, 5]
#unique_nums = list(set(nums))
#print(unique_nums)
#task2
#text = "hello hello world"
#words = text.split()
#counts = {}
#or word in words:
# counts[word] = counts.get(word, 0) + 1
#print(counts)
#task3
#strs = ['eat', 'tea', 'tan', 'ate', 'nat', 'bat']
#anagram_map = {}
#for word in strs:
# sorted_key = tuple(sorted(word))
# if sorted_key not in anagram_map:
# anagram_map[sorted_key] = []
# anagram_map[sorted_key].append(word)
#result = list(anagram_map.values())
#print(result)
#task4
#nums = [1, 3, 4, 5]
#n = 5
#full_set = set(range(1, n + 1))
#current_set = set(nums)
#missing_id = list(full_set - current_set)[0]
#print(f"Missing ID: {missing_id}")
#task5
#inventory = {"ID001": ("Laptop", 1200,
5),"ID002": ("Mouse", 25, 50)}
#target_id = "ID001"
#new_qty = 10
#item_data = inventory[target_id]
#name = item_data[0]
#price = item_data[1]
#inventory[target_id] = (name, price, new_qty)
#total_value = sum(item[1] * item[2] for item in
inventory.values())
#print(f"Updated Inventory for {target_id}:
{inventory[target_id]}")
pf2

Partial preview of the text

Download a COMPREHENSIVE REVIEWER FOR PROGRAMMING and more Translations Computer science in PDF only on Docsity!

#task 1 #nums = [1, 2, 2, 3, 4, 4, 5] #unique_nums = list(set(nums)) #print(unique_nums) #task #text = "hello hello world" #words = text.split() #counts = {} #or word in words:

counts[word] = counts.get(word, 0) + 1

#print(counts) #task #strs = ['eat', 'tea', 'tan', 'ate', 'nat', 'bat'] #anagram_map = {} #for word in strs:

sorted_key = tuple(sorted(word))

if sorted_key not in anagram_map:

anagram_map[sorted_key] = []

anagram_map[sorted_key].append(word)

#result = list(anagram_map.values()) #print(result) #task #nums = [1, 3, 4, 5] #n = 5 #full_set = set(range(1, n + 1)) #current_set = set(nums) #missing_id = list(full_set - current_set)[0] #print(f"Missing ID: {missing_id}") #task #inventory = {"ID001": ("Laptop", 1200, 5),"ID002": ("Mouse", 25, 50)} #target_id = "ID001" #new_qty = 10 #item_data = inventory[target_id] #name = item_data[0] #price = item_data[1] #inventory[target_id] = (name, price, new_qty) #total_value = sum(item[1] * item[2] for item in inventory.values()) #print(f"Updated Inventory for {target_id}: {inventory[target_id]}")

#print(f"Total Inventory Value: {total_value}")