You are viewing a single comment's thread. Return to all comments →
a=[int(x) for x in input().strip().split(' ')]
for i in range(1,len(a)):
while j>=0 and a[j]>key:
Do let me know if there is more finer solution in python.
loved the usage of *a. Learnt something new instead of using join()
You can't use join, the list doesn't contain strings but integers.
you can use join...
print(' '.join(str(i) for i in array))
it can be used because python provides str() functions which can convert interger to strings
I am glad you learned something new..Do let me know if i can help you with something.
Awesome! and thanks for the help offered. What would be in your opinion are good resources to learn advanced python concepts and also get better at Data Structures and Algorithms?
In case of Algorithms and Data structures I would reccomend you to learn from "CLRS" and even i do the same its a very good book.
In case of Advanced Python i suggest you to join online courses because it's a language the more you do the more you learn.
Cool. Thanks! I seem to be on the right path then
I did about the same, but using a sentinel at the front of the array:
n, amin = int(input()), -10**4
A = [2*amin] + list(map(int, input().split()))
for j in range(2, n+1):
i, a = j, A[j]
while a < A[i-1]:
A[i] = A[i-1]
i -= 1
A[i] = a
Thanks,learned something new.
for i in range(1, len(ar)):
for j in range(i):
k = ar[i]
ar[i] = ar[j]
ar[j] = k
I think its bubble sort!