Computer Science, asked by jagdish1581, 11 months ago

Program to print elements of a list [‘q’, ‘w’, ‘e’ ,’r’,’t’,’y’] in separate
lines along with element’s both indexes ( positive and negative).
Answer it fast

Answers

Answered by charanreddy2307
8

Explanation:

Input : n = 2

List_1 = [1, 2, 3, 4, 5, 6]

Output : List_1 = [5, 6, 1, 2, 3, 4]

We get output list after right rotating

clockwise given list by 2.

Input : n = 3

List_1 = [3, 0, 1, 4, 2, 3]

Output : List_1 = [4, 2, 3, 3, 0, 1]

For moving...

Python program to right rotate a list by n

# Returns the rotated list

def rightRotate(lists, num):

output_list = []

# Will add values from n to the new list

for item in range(len(lists) - num, len(lists)):

output_list.append(lists[item]) # Will add the values before

# n to the end of new list

for item in range(0, len(lists) - num):

output_list.append(lists[item]) return output_list

# Driver Code

rotate_num = 3

list_1 = [1, 2, 3, 4, 5, 6]

print(rightRotate(list_1, rotate_num

Hope it helps you ❤️

mark as brainlist number

Answered by vishakasaxenasl
4

Answer:

The following python program to print elements of a list ['q', ‘w’, ‘e’, ’r’, 't’,’y’] in separate lines along with elements’ indexes ( positive and negative).

arr = ['q ', 'w', 'e', 'r', 't', 'y']

for i in range(len(arr)):

  print(arr[i], i, -len(arr)+i)

Explanation

Let's understand the code above:

  • Our task is to print the elements of the given list in separate lines along with their positive and negative indexes.
  • So we start a for loop from 0 to the end of the list.
  • In each iteration of the loop, we print the element of each index and positive index.
  • For negative indexes, we have used a trick. First, catch the length of the array and make it negative and subtract the value of 'i' from it.
  • This will give the negative index of each element and print the output in separate lines.

#SPJ3

Similar questions