From bb0cc5f253715ae4ca3d1e1a3b9e03d6ee5db37b Mon Sep 17 00:00:00 2001 From: rainidhi09 <97797668+rainidhi09@users.noreply.github.com> Date: Sun, 16 Jan 2022 22:16:42 +0000 Subject: [PATCH] just to check if key os none or key does not exist . --- .../2_BubbleSort/bubble_sort_exercise_solution.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/algorithms/2_BubbleSort/bubble_sort_exercise_solution.py b/algorithms/2_BubbleSort/bubble_sort_exercise_solution.py index df838f7..6e8c7f9 100644 --- a/algorithms/2_BubbleSort/bubble_sort_exercise_solution.py +++ b/algorithms/2_BubbleSort/bubble_sort_exercise_solution.py @@ -3,8 +3,15 @@ def bubble_sort(elements, key=None): size = len(elements) for i in range(size-1): + if key is None: + print("please enter a key to start search.") + break swapped = False + breakloop =False for j in range(size-1-i): + if key not in elements[j]: + breakloop = True + break a = elements[j][key] b = elements[j+1][key] if a > b: @@ -12,6 +19,10 @@ def bubble_sort(elements, key=None): elements[j] = elements[j+1] elements[j+1] = tmp swapped = True + + if breakloop: + print("key is not correct") + break if not swapped: break @@ -25,4 +36,4 @@ def bubble_sort(elements, key=None): ] bubble_sort(elements, key='transaction_amount') - print(elements) \ No newline at end of file + print(elements) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy