Every line of 'python sort list of strings with numbers' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

By copying the Snyk Code Snippets you agree to

this disclaimer

40 def test_simple_sort(self): 41 input_lines = [ 42 '1', 43 '3', 44 '2', 45 ] 46 expected_output_lines = [ 47 '1', 48 '2', 49 '3', 50 ] 51 self.assertEqual(sort_lines(input_lines), expected_output_lines)

Important

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

66 def test_sort_with_decimals(self): 67 input_lines = [ 68 '1.5', 69 '1', 70 '2.5', 71 '2', 72 ] 73 expected_output_lines = [ 74 '1', 75 '1.5', 76 '2', 77 '2.5', 78 ] 79 self.assertEqual(sort_lines(input_lines), expected_output_lines)

59 def natural_sort(ls): 60 convert = lambda text: int(text) if text.isdigit() else text.lower() 61 alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] 62 return sorted(ls, key = alphanum_key)

909 """ Contains(self: Queue[T], item: T) -> bool """ 910 pass

38 def sort(a): 39 mergeSort(a,0,len(a)-1)

1 def bubbleSort(listofnumbers): 2 for allnumbers in range(len(listofnumbers)-1,0,-1): 3 for i in range(allnumbers): 4 if listofnumbers[i]>listofnumbers[i+1]: 5 a = listofnumbers[i] 6 listofnumbers[i] = listofnumbers[i+1] 7 listofnumbers[i+1] = a

5 def bubblesort(list): 6 swapped = True 7 while swapped: 8 print 9 print "New iteration..." 10 swapped = False 11 for i in range(len(list)-1): 12 if(list[i] > list[i+1]): 13 print "Index: " + str(i) + " - Swap " + str(list[i]) + " with " + str(list[i+1]) 14 tmp = list [i] 15 list[i] = list[i+1] 16 list[i+1] = tmp 17 swapped = True 18 print list 19 print "Nothing left to swap. Done" 20 return list

1 def gnome_sort(a): 2 i, j, size = 1, 2, len(a) 3 while i < size: 4 if a[i-1] <= a[i]: 5 i, j = j, j+1 6 else: 7 a[i-1], a[i] = a[i], a[i-1] 8 i -= 1 9 if i == 0: 10 i, j = j, j+1 11 return a

14 def shell_sort(collection): 15 """Pure implementation of shell sort algorithm in Python 16 :param collection: Some mutable ordered collection with heterogeneous 17 comparable items inside 18 :return: the same collection ordered by ascending 19 20 >>> shell_sort([0, 5, 3, 2, 2]) 21 [0, 2, 2, 3, 5] 22 23 >>> shell_sort([]) 24 [] 25 26 >>> shell_sort([-2, -5, -45]) 27 [-45, -5, -2] 28 """ 29 # Marcin Ciura's gap sequence 30 gaps = [701, 301, 132, 57, 23, 10, 4, 1] 31 32 for gap in gaps: 33 i = gap 34 while i < len(collection): 35 temp = collection[i] 36 j = i 37 while j >= gap and collection[j - gap] > temp: 38 collection[j] = collection[j - gap] 39 j -= gap 40 collection[j] = temp 41 i += 1 42 43 return collection

42 def counting_sort(strings, index): 43 length = len(strings) 44 45 if length == 0: 46 return strings 47 48 c = [0] * (k + 1) 49 b = [''] * length 50 51 for i in range(length): 52 c[get_digit(strings[i], index)] += 1 53 54 for i in range(1, k + 1): 55 c[i] += c[i - 1] 56 57 for i in range(length - 1, -1, -1): 58 b[c[get_digit(strings[i], index)] - 1] = strings[i] 59 c[get_digit(strings[i], index)] -= 1 60 61 return b