Computer Science, asked by ASweety1431, 11 months ago

Plzz help ..........

1)write a Python program code segment that prints the longest word in a list of words !!

2) write a program that rotates the element of list so that the element of the first index move to the second index the element in the second index move to the third index accept and the elements in the last index move to the first index in Python !!​

Answers

Answered by DMani3
6

1st qus:

def find_longest_word(words_list):

word_len = []

for n in words_list:

word_len.append((len(n), n))

word_len.sort()

return word_len[-1][1]

print(find_longest_word(["PHP", "Exercises", "Backend"]))

output: Exercises

2nd qus:

def findElement(arr, ranges, rotations, index) :

for i in range(rotations - 1, -1, -1 )

left = ranges[i][0] Ma

right = ranges[i][1]

if (left <= index and right >= index) :

if (index == left) :

index = right

else :

index = index - 1

return arr[index]

arr = [ 1, 2, 3, 4, 5 ]

rotations = 2

ranges = [ [ 0, 2 ], [ 0, 3 ] ]

index = 1

print(findElement(arr, ranges, rotations, index))

Output: 3

Mark Brainlieast


ASweety1431: Sorry there was some network issue
ASweety1431: u know Python programming language ???
ASweety1431: ?????
DMani3: i know python language
DMani3: why
ASweety1431: can u help me ??
ASweety1431: plzz
ASweety1431: yes or no ??????
DMani3: s tell
ASweety1431: yaar
Answered by sumadevasia
1

Answer:

1) def find_longest_word(words_list):

   word_len = []

   for n in words_list:

       word_len.append((len(n), n))

   word_len.sort()

   return word_len[-1][1]

print(find_longest_word(["PHP", "Exercises", "Backend"]))

2) def findElement(arr, ranges, rotations, index) :  

     

   for i in range(rotations - 1, -1, -1 ) :  

     

       # Range[left...right]  

       left = ranges[i][0]  

       right = ranges[i][1]  

 

       # Rotation will not have  

       # any effect  

       if (left <= index and right >= index) :  

           if (index == left) :  

               index = right  

           else :  

               index = index - 1

         

   # Returning new element  

   return arr[index]  

 

# Driver Code  

arr = [ 1, 2, 3, 4, 5 ]  

 

# No. of rotations  

rotations = 2

 

# Ranges according to  

# 0-based indexing  

ranges = [ [ 0, 2 ], [ 0, 3 ] ]  

 

index = 1

 

print(findElement(arr, ranges, rotations, index))

Mark me as the brainliest!

Similar questions