How can I compare one element with the next one in a sorted list, and print out their differences. Any help would be appreciated.
Eg:
lst = [3.18,10.57,14.95,...]
10.57 - 3.18 = 7.39
14.95 - 10.57 = 4.38
...
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are manipulating numerical data, consider using numpy
You can convert it back to list if you have to:
Otherwise you can iterate over it just like you iterate over a list:
EDIT: the five solutions I timed were pretty close to each other, so choose the one that’s easier to read