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]
3 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]3 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]3 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
1. What is material science?
Murljashka [212]

Answer:

Explanation:

The study of the properties of solid materials and how those properties are determined by a material’s composition and structure is material science.

6 0
3 years ago
Read 2 more answers
Which term refers to actions that you would typically perform on a computer to revive it even if it functions in an unexpected m
sweet-ann [11.9K]
You'd usually reboot a PC if it malfunctions.
6 0
3 years ago
The smallest unit of a spreadsheet, and it is formed by the intersection of a row and a column.
slega [8]
The answer would be: B. Cell
5 0
3 years ago
How do you flash your high beams ?​
Bad White [126]

Answer: to flash your high beams you have to basically put on and turn them off really quickly here is what the button looks like :)

Hope this helps you out :)

7 0
3 years ago
Read 2 more answers
Identify way in which computer are used in personnel management
Lyrx [107]

The main roles of computer in human resource management are decreasing time complexity, flexibility, record keeping problem etc. HRM system process lots of data everyday with the help of computer. This data processed easily without any fear of data loss so computer a vital role in human resource management system. The usage of computer in human resource management can be usually referred to as management information system. It can also be called as human resource information system. Usually what a computer does, it converts all the data or we can say raw data into meaningful and usable information required by the manager to take decisions, and for planning and control.

please I need brainliest thanks

I hope this helps

4 0
3 years ago
Read 2 more answers
Other questions:
  • The expressionvecCont.empty() empties the vector container of allelements.
    13·1 answer
  • In this context, the word “session” refers to _____.
    5·2 answers
  • A formal log-on procedure is the operating system’s last line of defense against unauthorized access.
    10·1 answer
  • Programming assignment (100 pts): In the C++ programming language write a program capable of playing Tic-Tac-Toe against the use
    14·1 answer
  • A document created by the scriptwriter that contains general information about a program is called _____.
    15·1 answer
  • What is the importance of human flourishing to science and technology?​
    8·1 answer
  • Add me on blizzard none of my friends play ow<br> NADERJABER#2530
    8·1 answer
  • You are to calculate the property tax for tax payers. You will ask the county tax clerk if they want to run the program and init
    9·1 answer
  • Explain how communication is smooth and efficient working​
    13·2 answers
  • What is installing?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!