Question

In: Computer Science

Given the following coordinates: (f, 9), (z, 2), (t, 4), (x, 8), (b, 1), (m, 7)....

Given the following coordinates: (f, 9), (z, 2), (t, 4), (x, 8), (b, 1), (m, 7).

Sort the coordinates in Python (in ascending order) by comparing the first part of the

coordinates. You may use the sort() function in Python.

Solutions

Expert Solution

# sorting the list coordinates using first coordinate part string or character
# for sorting strings bubble sorting is used
def SortFirstCoordinate(lst):
   listlen = len(lst)   #length for list
   for i in range(0,listlen):
       for j in range(0, listlen-i-1):
           if (lst[j][0] > lst[j + 1][0]):   #checking first coordinate is greater than next coordinate if true then swap both coordinates
               tmpvar = lst[j]
               lst[j]= lst[j + 1]
               lst[j + 1]= tmpvar
   return lst   #returning sorted list

#main code starts
#list with coordinates
lst =[('f', 9), ('az', 2), ('t', 4),('x', 8), ('b', 1), ('m', 7)]
#displaying sorted list by first coordinate
print(SortFirstCoordinate(lst))


Related Solutions

The temperature at a point (x,y,z) is given by T(x,y,z)=200e^(-x^2-y^2/4-z^2/9) , where T is measured in...
The temperature at a point (x,y,z) is given by T(x,y,z)=200e^(-x^2-y^2/4-z^2/9) , where T is measured in degrees Celsius and x,y, and z in meters. just try to keep track of what needs to be a unit vector. a) Find the rate of change of the temperature at the point (1, 1, -1) in the direction toward the point (-5, -4, -3). b) In which direction (unit vector) does the temperature increase the fastest at (1, 1, -1)? c) What is...
Find the derivative of the function. A) f(x)=(2+x^3)^2/3 B) h(t)= (t^4-1)^9(t^3+1)^8 C) y = e4x sin(x)...
Find the derivative of the function. A) f(x)=(2+x^3)^2/3 B) h(t)= (t^4-1)^9(t^3+1)^8 C) y = e4x sin(x) D) y= (x^2+2/x^2-2)^3
1: Given that f(4) = 6 and f'(x) = 2/x2+9 for all x. a) Use a...
1: Given that f(4) = 6 and f'(x) = 2/x2+9 for all x. a) Use a linear approximation or differentials to estimate f(4.04) b) Is your estimate in part (a) too large or too small? Explain. 2: a) Given f(x) = (x + 3)sinx, find f'(π) using logarithmic differentiation. b) Find the value of h'(0) if h(x)+xsin(h(x))= x2+4x-π/2
A=[ 7 8 -2 -6 7 4 1 ; 2 4 -4 -13 9 9 -12...
A=[ 7 8 -2 -6 7 4 1 ; 2 4 -4 -13 9 9 -12 ; 6 6 0 -9 8 9 -4 ; 1 8 -14 -22 5 8 -1 ; 4 9 -10 -14 7 4 -1] B=[ 19 4 4 14 -3 -7 -5 ; 21 -6 -5 10 14 -2 4 ; 22 -4 5 13 5 -6 4 ; 41 20 0 26 11 -1 -27 ; 29 14 -2 20 3 -4 -19]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5] D = [1, -9, 5, -3] E = [3, 3, -1] Uz = 1/|z| ^z d(X,Y) = (Rθ) d = diameter R = Radius θ = Theta Find a. Uc b. d (D, C) c. Let P = B + 3E, UP = d. A x B e. 3B x E f. C x D
WG G 1 M 2 M 7 F 4 M 12 F 2 M 1 M...
WG G 1 M 2 M 7 F 4 M 12 F 2 M 1 M 10 F 1 M 2 M 3 M 1 M 1 M 2 M 1 M Assume that : The first column is the weight gain of the people in the quarantine in the first week in kilogram (WG) .    The second column is describing the gender whether it was male or female (G) . Q: Is there any statistical evidence that the...
A set of data has the following coordinates t 0 1 3 4 7 y 2...
A set of data has the following coordinates t 0 1 3 4 7 y 2 4 5 7 10 a) Find the least-squares fit to this data by a linear function of t (that is, find constants c1,c0 so that y(t) = c1t + c0 is the best linear fit to this set of data). b) Find the equation of the best quadratic fit to the same set of data. Then find the equation of the polynomial of smallest...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7 9 7 4 6 9 9 -5.48x + 0.17 5.48x + 0.17 -0.17x + 5.48 0.17x + 5.48
Find the coordinates of the point (x, y, z) on the plane z = 4 x...
Find the coordinates of the point (x, y, z) on the plane z = 4 x + 1 y + 4 which is closest to the origin.
Show that f(x) = x^4+x^3+3x^2+7x−8 is irreducible over Z.
Show that f(x) = x^4+x^3+3x^2+7x−8 is irreducible over Z.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT