A function to see if one list is a shallow copy of other

Assignment Help Computer Engineering
Reference no: EM132942

Question

Modify this function to check to see if one list is a shallow copy of other.


def first_mismatch(lst1, lst2)-
'''(list of objects, list of objects) -> int

Return the index of the first item at which the values of lst1 and lst2
differ. Return -1 if no differences are found.

>>> first_mismatch(['a', 'b', 'c'], ['a', 'd', 'c'])
1
>>> first_mismatch(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])
3
>>> first_mismatch(['a', 'b', [1]], ['a', 'b', [1]])
-1
'''

shorter = min(len(lst1), len(lst2))
for idx in range(shorter):
if lst1[idx] != lst2[idx]:
return idx

if len(lst1) == len(lst2):
return -1

return shorter

Reference no: EM132942

Questions Cloud

Display the miles per gallon obtained for each tankful : Display the miles per gallon obtained for each tankful
What do you understand by the term branding : What do you understand by the term branding The organisational brand defines how the organization best meets its customers' needs in unique and compelling ways. Discuss the statement with reference to relevant brand indentities
What is bobs private key : What is Bob's private key?
Computation of basic eps for the year 2002 : What number of shares can be used in the computation of basic EPS for the year 2002?
A function to see if one list is a shallow copy of other : A function to see if one list is a shallow copy of other
Evaluate the amount of taxes paid in country : Evaluate the amount of taxes paid in Country
Arrays and control structures important tools in programming : Arrays and control structures important tools in programming.
Make entries in the journals of the capital projects fund : Make the appropriate entries in the general journals of the Capital Projects Fund
Create an xml document containing information : Create an XML document containing information.

Reviews

Write a Review

Computer Engineering Questions & Answers

  What is best-case complexity of the algorithm

What is best-case complexity of the algorithm?

  Describe the mechanics of Buffer overflows

Prepare a complete tutorial, including an analogy to describe the mechanics and a graphic to support your analogy, on one of the subsequent areas

  How to produce a wired and wireless network plan

How to produce a wired and wireless network plan

  Declare amdahls law

Declare Amdahl's law

  Create an employee class with enough numbers

Create an Employee class with enough numbers.

  Findout which one is false statement

Findout which one is false statement.

  Write a program that mimics a flop-turn-river of poker game

Write down a program that mimics a flop-turn-river of a poker game. I must have three buttons titled Deal, Shuffle and Start Over.

  What is mno

What is MNO.

  Why is an object (oop) a module

Why is an object (OOP) a module

  Which loop arrangement be best for accessing an array

Which loop arrangement be best for accessing an array.

  How can sophie use applocker

How can Sophie use AppLocker.

  Write a function called is_anagram

Write a function called is_anagram.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd