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
The technical relationship between inputs and outputs, which is needed to understand the difference between the short run and th
MrRa [10]
<span>The technical relationship between inputs and outputs, which is needed to understand the difference between the short run and the long run, is called a production function.

Hope I helped ;)
</span>
3 0
3 years ago
Cache memory and RAM both are based on transistor based then why cache memory is needed if we already have RAM (Random Access Me
attashe74 [19]
I would tell you but nah because I do math so yeah thanks yes
6 0
3 years ago
Help!! me!! plsssssssssssssssssssssssssssssssssss
Maslowich

Answer:

e,f,g, and h

Explanation:

5 0
3 years ago
The ideal light to use is?
alekssr [168]

Answer:

i think that the idea light to use is a front light?

it can lighten a dark room depending on the radius of the light or the refletor, im not sure if this is 100% right but i hope this helps you in some way!

×║hope this helps!║×

6 0
3 years ago
Uses of keyboard as a input device
KATRIN_1 [288]

helps us for typing letters, numbers and symbols etc.

3 0
3 years ago
Read 2 more answers
Other questions:
  • The conceptual phase of any system or just the software facet of a system best describes the sdlc
    9·1 answer
  • If you touch a downed power line covered or bare, what’s the likely outcome?
    10·2 answers
  • How can touch typing quickly but accurately improve your earnings (the money you can make)
    15·2 answers
  • Online companies typically have a(n) _________ on their websites that clearly states what information is collected from users an
    7·1 answer
  • What is the best way of farming exotics in destiny?
    12·2 answers
  • Dan wants to use some of his friend's printed photos of sea creatures for a school multimedia project. Which input device is bes
    11·1 answer
  • How to turn off microsoft teams message notifications
    13·1 answer
  • When a cpu executes instructions as it converts input into output, it does so with _____.
    8·1 answer
  • ASAP PLEASE the online research you did to describe how Senet is related to the culture and historical period when it was create
    9·1 answer
  • What information most likely presents a security risk on your personal
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!