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
In a word processing program, under which tab or menu option can you adjust the picture brightness?
Otrada [13]
B. format because changing the brightness of the photo is changing its default format
5 0
2 years ago
Read 2 more answers
The total number of possible keys for des is _________, which a modern computer system can break in a reasonable amount of time.
FinnZ [79.3K]
The answer is two. Most people think it's one but it's 2
3 0
3 years ago
In a spreadsheet, there are many features that help you edit quickly. True False
9966 [12]

Answer:

True

Explanation:

There are many form a quick editing

i hoped this helped

;)

7 0
3 years ago
Assume that ip has been declared to be a pointer to int and that result has been declared to be an array of 100 elements . Assum
Bogdan [553]

Answer:

The expression of this question can be given as:

Expression:

*ip + 1

Explanation:

In this question, it is given that ip variable has been declared and initialized and the ip variable is in the first half of the array. It finds the expression whose value is after the element of the array that ip points. So the expression to this question is *ip + 1. Where * is used to define ip variable as a pointer and its value is increased by 1 that is given in the question.

7 0
3 years ago
which consumable would be used with a 3d printer? group of answer choices filament print ribbon toner cartridge ink
Anna35 [415]

Answer:

Filament

Explanation:

Filament is the plastics that 3d printers use to make objects.

7 0
1 year ago
Other questions:
  • How many buttons does a gamecube controller have?
    7·1 answer
  • When typing the Works Cited in a report, set a .5" ______ indent. *
    12·1 answer
  • Idea citizen activation
    9·2 answers
  • Which statement best describes a transition in PowerPoint?
    12·1 answer
  • Which of the following is a requirement for the Safety Data Sheet (SDS)?​
    5·1 answer
  • Differentiated instruction is designed to educate children through ________ techniques in order to ensure every student is being
    13·1 answer
  • Which of these organs is not found in the excretory system
    7·2 answers
  • NumA = 3 <br>numB = 2<br>Result = numA ** numB
    12·1 answer
  • First person to make me laugh will get brainliest.​
    10·2 answers
  • Which of the following class definition defines a legal abstract class Group of answer choices public class Rectangle abstract {
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!