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
Three variables, x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts th
Gelneren [198K]
The answer is 45boobg
3 0
3 years ago
Read 2 more answers
Which is an unbound form with menu options for navigating a database?
melisa1 [442]
The answer B. a switchboard
6 0
3 years ago
Read 2 more answers
What symbol do we use to assign a value to a variable or constant in algorithms?
jekas [21]

The symbol that we do use to assign a value to a variable or constant in algorithms is =.

<h3>What is used to assign a constant to a variable?</h3>

The const keyword is known to be one that tends to specifies a variable or object value that is known to be  constant.

In computing and computer programming, there are different kinds of variables as well as symbols that are used for different purposes.

Note that if you assign a variable, you need to use the = symbol and thus The symbol that we do use to assign a value to a variable or constant in algorithms is =.

Learn more about algorithms from

brainly.com/question/13800096

#SPJ1

3 0
1 year ago
Which is an example of an effective study skill?
Lelu [443]

Answer:

the making note cards and quizzing yourself

Explanation:

5 0
2 years ago
Read 2 more answers
(1) Experiment Purpose
ra1l [238]

An Output report is known to be the various  findings that has been generated or it is said to be the result of a given program outcome.

<h3>What is an output report?</h3>

An output is known to be a file that has been produced by the system when a user is said to have submitted a Program, Report Set, etc. for execution.

Note that to be able to compile the GPSSWorld program, one has to use a statistical software to create the output and charts, and then one can copy and paste the results unto any given  word processor software where one can construct a table for it.

Learn more about output reports from

brainly.com/question/11599232

#SPJ1

3 0
1 year ago
Other questions:
  • A file to which information is written is referred to as a(n) ____ file.
    8·1 answer
  • Please answer this I know that no one else does but I can't think right now
    10·1 answer
  • A tool you might use to manipulate an image, such as a photograph, into a seamless repeating texture would be:
    7·2 answers
  • How will using ascending order on a field that contains dates sort a list?
    12·2 answers
  • Carrie works on a help desk and is assigned a ticket that was automatically generated by a server because of an error. The error
    14·2 answers
  • Raid level 6 is basically the same as RAID level 5, but it adds a second set of parity bits for added fault tolerance and allows
    7·1 answer
  • 3.
    5·1 answer
  • Copyright applies to work at the time it was produced, written, and developed. True or False?
    10·2 answers
  • String[][] arr = {{"Hello,", "Hi,", "Hey,"}, {"it's", "it is", "it really is"}, {"nice", "great", "a pleasure"},
    11·1 answer
  • During the ___ phase of a software development project, members broadly define the features that the software should include
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!