A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Python program to find the difference between consecutive numbers in a given list
Q:

Write a Python program to find the difference between consecutive numbers in a given list

0

 Write a Python program to find the difference between consecutive numbers in a given list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def diff_consecutive_nums(nums):
    result = [b-a for a, b in zip(nums[:-1], nums[1:])]
    return result

nums1 = [1, 1, 3, 4, 4, 5, 6, 7]
print("Original list:")
print(nums1)
print("Difference between consecutive numbers of the said list:") 
print(diff_consecutive_nums(nums1))

nums2 = [4, 5, 8, 9, 6, 10]
print("\nOriginal list:")
print(nums2)
print("Difference between consecutive numbers of the said list:") 
print(diff_consecutive_nums(nums2))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now