1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
prisoha [69]
2 years ago
10

Write a function swap that swaps the first and last elements of a list argument. Sample output with input: 'all,good,things,must

,end,here' ['here', 'good', 'things', 'must', 'end', 'all']
Computers and Technology
2 answers:
asambeis [7]2 years ago
8 0

Answer:

def swap(li):

   n=len(li)

   li[0],li[n-1]=li[n-1],li[0]

   return li

Explanation:

Python is very user friendly language and and this provides numerous functions and in-built services. In the above function, i have created a method which is taking an argument li and we can find the length of li by using method len() which is then stored in variable n. Now we have to swap first and last element so, first element of li is li[0] and last is li[n-1]. Python provides one more utility in which we can change values of 2 elements simultaneously by separating them with comma. So, we put the value of last element in first and value of first in last which saved many lines of code.

zubka84 [21]2 years ago
7 0

Answer:

li=list(map(str,input().strip().split()))#taking input of the string.

#swapping first and last element.

temp=li[0]

li[0]=li[-1]

li[-1]=temp

print(li)#printing the list.

Explanation:

I have taken the list li for taking the input of strings.Then after that swapping first and last element of the list.Then printing the list.

You might be interested in
5.8.1: Modify an array parameter. Write a function SwapArrayEnds() that swaps the first and last elements of the function's arra
viktelen [127]

Answer:

see explaination

Explanation:

#include<stdio.h>

/* Your solution goes here */

//Impllementation of SwapArrayEnds method

void SwapArrayEnds(int sortArray[],int SORT_ARR_SIZE){

//Declare tempVariable as integer type

int tempVariable;

if(SORT_ARR_SIZE > 1){

tempVariable = sortArray[0];

sortArray[0] = sortArray[SORT_ARR_SIZE-1];

sortArray[SORT_ARR_SIZE-1] = tempVariable;

}

}

int main(void) {

const int SORT_ARR_SIZE = 4;

int sortArray[SORT_ARR_SIZE];

int i = 0;

sortArray[0] = 10;

sortArray[1] = 20;

sortArray[2] = 30;

sortArray[3] = 40;

SwapArrayEnds(sortArray, SORT_ARR_SIZE);

for (i = 0; i < SORT_ARR_SIZE; ++i) {

printf("%d ", sortArray[i]);

}

printf("\n");

return 0;

}

Please go to attachment for the program screenshot and output

3 0
2 years ago
PLS HELP ;CC
icang [17]

Answer:

a

early photographers who were first painters

Explanation:

The Rule of Thirds is a compositional technique which states that image painting, photograph, graphic design should be divided into nine equally proportioned boxes by creating a grid with two vertical and two horizontal lines. The rule of third helps in making the picture more attractive and balanced

The rule of thirds was first used in landscape paintings by painters as early as 1797.

5 0
3 years ago
There are information that are in the web view source that may not appear on the web page such as meta name. In addition there c
SCORPION-xisa [38]

Answer:

True on a web page such meta name will not appear in web view source and irrelevant information will be displayed.

Explanation:

Basically web page source is compiled version of HTML script so the end-user he or she tries to view pages system will show only in HTML.

so meta name information and active object information will not be displayed while viewing the web source code instead of that the irrelevant informant ions will be displayed and end-user cannot under anything out of the web source code.

Moreover, even the client side validation script also will not be displayed.

Only HTML will be displayed  

3 0
3 years ago
The events that happen in a story are called the _________________.
RUDIKE [14]

Answer: B) plot

Explanation:

4 0
2 years ago
Read 2 more answers
Think about the pseudocode that you developed for your adventure game in this unit. Would it have been easier to create a flowch
katovenus [111]

Answer:

it may not be easy

Explanation:

because am using a phone not a cuputer

5 0
2 years ago
Other questions:
  • What the address for dns server that the eorkstation will use?
    10·1 answer
  • What identifies available computers through the internet?
    14·1 answer
  • Mr. Green maintains a spreadsheet containing data on all of his employees, including name, job profile, monthly salary, and home
    15·1 answer
  • Which of the following feature are parts of Toyota’s safety system?
    10·1 answer
  • You are contacted by a project organizer for a university computer science fair. The project organizer asks you to hold a forum
    10·1 answer
  • What is the effect of this program?
    5·1 answer
  • Which attribute defines the file name for the specific image in an image tag??
    13·1 answer
  • Which of the following is true regarding the use of instance variable j in class B1?
    15·1 answer
  • Any device that uses light to read and write information.
    9·2 answers
  • Can somebody please help me with these few questions?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!