Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HI I need help on this assignment can some please help me. I supposed to use slice notation but I dont know how to use

HI I need help on this assignment can some please help me. I supposed to use slice notation but I dont know how to use it in this program to iterating over a list.

Modify the program (copied from above) using slice notation to iterate over a copy of the list.

nums1 = [] nums2 = []

user_input = input('Enter first set of numbers: ') tokens = user_input.split() # Split into separate strings

# Convert strings to integers for pos, val in enumerate(tokens): nums1.append(int(val)) print('%d: %s' % (pos, val))

user_input = input('Enter second set of numbers:') tokens = user_input.split()

# Convert strings to integers print() for pos, val in enumerate(tokens): nums2.append(int(val)) print('%d: %s' % (pos, val)) # Remove elements from nums1 if also in nums2 print() for val in nums1: if val in nums2: print('Deleting %d' % val) nums1.remove(val)

# Print new numbers print(' Numbers only in first set:', end=' ') for num in nums1: print(num, end=' ')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

Students also viewed these Databases questions