answer to the above question : -
split() is a string method in python which returns a list of all the words in the string separated on the basis of the specified delimiter inside the split().
If nothing is specified then,string will return a list of words separated on a basis of empty space.
for example : -
this will give output a list of all the words in the string splitted on the basis of space character.
output : -
another example : -
here the delimeter inside the split() method is '-' so, it will return list of words sperated by '-'.
output : -
and indices above in the question are the indices of the returned list of words.
for example: -
output for above will be : -
0 is the first index ,
1 is the second index and -1 is the last index in the list of words of the string.
code for understanding : -
# string using for the example
url = 'https://docs.python.org/3/tutorial/interpreter.html'
print(url.split('//')[-1]) #splitting on the basis of '//' then
taking last element
#first splitting on '//' and then taking last element of the list
and then splitting
#again on '/'
print(url.split('//')[-1].split('/'))
#splitting on '//' then taking last element then splitting again on
'/' then taking first element
print(url.split('//')[-1].split('/')[0])
#splitting on '//' then taking last element then splitting again on
'/' then taking first element
# then splitting on '.' again
print(url.split('//')[-1].split('/')[0].split('.'))
#splitting on '//' then taking last element then splitting again on
'/' then taking first element
# then splitting on '.' again then taking the last element
print(url.split('//')[-1].split('/')[0].split('.')[-1])
print()
print("---------------------------------------------------------------------")
print()
print(url.split('://')) #splitting string on the basis of
'://'
print(url.split('://')[-1]) #splitting on the basis of '://' then
taking last element
#first splitting on '://' and then taking last element of the list
and then splitting
#again on '/'
print(url.split('://')[-1].split('/'))
#splitting on '://' then taking last element then splitting again
on '/' then taking first element
print(url.split('://')[-1].split('/')[0])
#splitting on '://' then taking last element then splitting again
on '/' then taking first element
# then splitting on '.' again
print(url.split('://')[-1].split('/')[0].split('.'))
#splitting on '://' then taking last element then splitting again
on '/' then taking first element
# then splitting on '.' again then taking the last element
print(url.split('://')[-1].split('/')[0].split('.')[-1])
code screenshot : -
code output : -
please go through the above code and otuput for better understanding.
If this helped then please upvote and comment for any further queries
Thankyou !
print("My name is Anonymous".split())
['My', 'name', 'is', 'Anonymous']
print("My-name-is-Anonymous".split('-')).
['My', 'name', 'is', 'Anonymous']
print("My-name-is-Anonymous".split('-')) print("My-name-is-Anonymous".split('-')[0]), print("My-name-is-Anonymous".split('-')[1]), print("My-name-is-Anonymous".split('-')[-1]),
['My', 'name', 'is', 'Anonymous'] My name Anonymous
1 # string using for the example, 2 url = "https://docs.python.org/3/tutorial/interpreter.html' 3 print(url.split('IT')[-1]) #splitting on the basis of '//' then taking last element 4 #first splitting on //' and then taking last element of the list and then splitting #again on '/' print(url.split('//')[-1].split('7')). 7 #splitting on '//' then taking last element then splitting again on '/' then taking first element print(url.split('//)[-1].split(T)[@]) 9 #splitting on '/' then taking last element then splitting again on '/' then taking first element 10 # then splitting on '.' again 11 print(url.split('IT')[-1].split('7')[0].split('.')) 12 #splitting on '71' then taking last element then splitting again on '/' then taking first element 13 # then splitting on '.' again then taking the last elementi 14 print(url.split('IT')[-1].split('7")[0].split("'.')[-1]), print() --------------------------" 17 print() 18 print(url.split('://')) #splitting string on the basis of ':// print(url.split('://')[-1]) #splitting on the basis of '://' then taking last element 20 #first splitting on '://' and then taking_Last element of the list and then splitting #again on '/' print(url.split('://')[-1].split('7')) 23 #splitting on '://' then taking Last element then splitting again on '/' then taking first element 24 print(url.split('://')[-1].split('/')[0]), 25 #splitting on '://' then taking Last element then splitting again on '/' then taking first element 26 # then splitting on '.' again 27 print(url.split('://')[-1].split('7')[0].split('.')); 28 #splitting on '://' then taking last element then splitting again on '/' then taking first element 29 # then splitting on '.' again then taking the last element 30 print(url.split('://')[-1].split('7')[@].split('.')[-1]), 16 print("------------------------------------------------------------ splitting itting on, jf-11. split Laste leme the last 24-11) 31
docs.python.org/3/tutorial/interpreter.html ['docs.python.org', '3', 'tutorial', 'interpreter.html') docs.python.org ['docs', 'python', 'org'] org - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ('https', 'docs.python.org/3/tutorial/interpreter.html') docs.python.org/3/tutorial/interpreter.html ['docs.python.org', '3', 'tutorial', 'interpreter.html') docs.python.org ['docs', 'python', 'org'] org
python 3 explain the code and whafs split doing here im confused on what it returns...
3. What does this code do? Write an explanation in English python n=1 while (n <1000): print(n) n-n
PYTHON: Im stuck here, big O notation and runtime. What is it and Why are they those? Please look at the pic, need help as Im confused. Thank You! def method3(n): for i in range(n): for j in range(100): for k in range(n): print(i+j+k) What is the runtime (tightest/closest bound in terms of O) for the above python function (method 3)? Please briefly explain. Enter your answer here def method4(n): for i in range(n): for j in range(n, o, -2):...
Python 3. Help please. Here is my current code. What can I do to fix it? I list=[1,2,2,3,4,5] d = {} for item in list: if item in d: return True d[item] = True return False Exercise 11.4. If you did Exercise 10.7, you already have a function named has_duplicates that takes a list as a parameter and returns True if there is any object that appears more than once in the list. Use a dictionary to write a faster,...
Can someone explain what Im doing wrong? I did -(8.134)(235)ln(1.91X10^22) and got -98.06 Question 12 At a certain temperature, 235 K, Kp for the reaction, 4 NH3(g) + 5 O2 <=> 4 NO(g) + 6 H2O(g), is 1.91 x 1022. Calculate the value of AG° in kJ for the reaction at this temperature. Selected Answer: ® -98.06 Correct Answer: -100 + 1%
please explain very well.Thanks Question 3) What is the output of the following code? (4 marks) #include <stdio.h> int main(void) Output: int i; for (i = 0;i<4; i++) static int a = 0; int b = 0; a++; b++; printf("%d %d", a,b); 11213141
Write code in Python: explain with comments Starting with two one-digit positive integers a and b, consider the sequence in which the next number is the digit in the ones place of the sum of the previous two numbers. For example, if a = 1 and b = 1, the sequence is 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, … Write a function mystery(a, b) that returns the length of the sequence...
Write code in Python: explain with comments Starting with two one-digit positive integers a and b, consider the sequence in which the next number is the digit in the ones place of the sum of the previous two numbers. For example, if a = 1 and b = 1, the sequence is 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, … Write a function mystery(a, b) that returns the length of the sequence...
What will be printed upon running following code: alist = [3, 50, "Kity", [50, 52, "Rover"], [ ], 3.14, False, 'a'] print(len(alist[3]))alist = [3, 50, "Kity", [50, 52, "Rover"], [ ], 3.14, False, 'a'] print(len(alist[3])) 8 7 2 an error 3 Select the best reason why the code below returns True, False, False respectively? a = 256 b = 256 print(id(a) == id(b)) c = 5.1 d = 5.1 print(id(c) == id(d)) x = 257 y = 257 print(id(x) ==...
okay so here is my c++ code and the errors im really stuck on fixing what i did wrong it seems to be the same repeated error our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses A your program should use a loop and your morse code printing...
Python 3 Coding Functions: Here is any code required to help code what is below: def pokemon_by_types(db, types): new_db = {} for pokemon_type in types: for key in db: # iterate through all the type in types list if db[key][1] == pokemon_type or db[key][2] == pokemon_type: if key not in new_db: new_db[key] = db[key] return new_db I need help coding the functions listed below in the image: Thank you get types(db): Given a database db, this function determines all the...