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
Write a program using integers user_num and x as input, and output user_num divided by x three times.Ex: If the input is:20002Th
HACTEHA [7]

Answer:

Following are the code to the given question:

user_num = int(input())#defining a variable user_num that takes input from user-end

x = int(input())#defining a variable x that takes input from user-end

for j in range(3):#defining for loop that divides the value three times

   user_num = user_num // x#dividing the value and store integer part

   print(user_num)#print value

Output:

2000

2

1000

500

250

Explanation:

In the above-given program code two-variable "user_num and x" is declared that inputs the value from the user-end and define a for loop that uses the "j" variable with the range method.

In the loop, it divides the "user_num" value with the "x" value and holds the integer part in the "user_num" variable, and prints its value.  

5 0
3 years ago
A company wants to ensure that the validity of publicly trusted certificates used by its web server can be determined even durin
Natali [406]

Answer: OCSP

Explanation:

Ocsp(online certificate status protocol) is used to maintain the security status of the server and also to determine the status of SSL/TLS certificates used by the webserver.

5 0
3 years ago
Dani wants to create a web page to document her travel adventures. Which coding language should she use? HTML Java Python Text
Anna [14]

Answer:

HTML, CSS, JavaScript, python, SQL

Explanation:

To create a web page for her travel adventures Dani has to use HTML and CSS to design the page's layout. A beautiful simple design such as one which shows photos of her on her travel destinations, and a paragraph for her to write a little story on her travels would do.

Dani needs JavaScript to animate the photos she's going to post on the page. Dani also should use python to build the backend of her page so she can write codes to save and access her documented adventures from the database. She should use a database language like SQL to save all of her adventures so she can view them at a later time for the memories.

7 0
3 years ago
Write the correct word to complete the sentence:
spayn [35]

Answer:

Legend

Explanation:

In English language, a legend can be defined as a traditional narrative or story that is written about a particular person or past events and it's likely to either be a myth or historical facts. Thus, a legend is sometimes an unrealistic story or narration that describe a particular person or an extraordinary event that occured in the past. Also, it's a story about a particular figure, past human events or actions whose origin is unknown, unproven and undocumented in real history

Additionally, the word "legend" was derived from the Latin word "legendus" which simply means something which should be read.

Hence, the most appropriate word to complete the sentence is a legend because there are no proven and documented or written records about how Bolster the Giant terrorised the people of Cornwall. Thus, the complete mythical sentence is then written as;

"According to legend, Bolster the Giant terrorised the people of Cornwall.​"

8 0
3 years ago
Hey all! Adobe here. I think that we should talk about After Effects 2021 and After Effects CC 2021. With BRAND NEW FEATURES, (A
ella [17]

Answer:

thx ur the best

7 0
3 years ago
Other questions:
  • Given parameters b and h which stand for the base and the height of an isosceles triangle (i.e., a triangle that has two equal s
    8·1 answer
  • What executable programs have names that are just one character long, and what do they do??
    5·1 answer
  • IT investments can lead to developing IT capabilities and dynamic IT competencies, which can lead to achieving the following six
    5·1 answer
  • Which element is included in the shot breakdown storyboard? Which element is included in the shot breakdown storyboard?
    8·1 answer
  • Linda is searching for a new job. Which information would her potential employers likely review in her social profile?
    14·2 answers
  • Ben is writing a paper for his college history class, and he wants to include some information he found on a Web site. What are
    5·1 answer
  • The two objects representing values FALSE & TRUE are called _________Integers​
    10·1 answer
  • is a measurement that quantifies how much information can be transmitted over the network. A. Memory B. DMZ C. Bandwidth D. Clou
    10·1 answer
  • Features of Python are *
    9·1 answer
  • According to programming best practices, how should you handle code that needs to be repeated several times in a program?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!