on 12-Oct-2018 (Fri)

Flashcard 3415723871500

Question
In python, you have sets, s={1,2,3} and t={1}, check (expect True) if all items in t are also in s.
s.issuperset(t)

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3415955344652

Question
In regular expressions, using grep, match for the words kremlin, krypton, krn, krzn, in file test.txt?
grep -w 'kr.*n' test.txt
^^ note the use of "." followed by "*" to search for 0 or more of any char

status measured difficulty not learned 37% [default] 0
5. Regular Expressions
-w 'cr[a-m]*t' Matches the words craft , credit , and cricket . The * means to match any number of the previous character, which in this case is any character from a through m . grep -w 'kr.*n' <span>Matches the words kremlin and krypton , because the . matches any character and the * means to match the dot any number of times. egrep -w '(th|sh).*rt' Matches the words shirt , short , and thwart . The | means to match ei

Flashcard 3416061775116

Question
In algorithms, between recurtion and iteration, which one is usually more processor intensive (hint: thing of case where it fails to terminate/is infinite)?
interation

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3416064920844

Question
In algorithm, time complexity is measured in [...] notation
big-O
^^ FYI, O stands for Order-magnitude

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3416093232396

Question
In algorithms, what is the big-O time complexity of an algorithm that shrinks the input size in half on each iteration (e.g. finding an element in a sorted array)?
O(logn)
^^ note that logn is, log base2 n

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3416096378124

Question
In algorithms, what is the time complexity of iterating through all items in a single loop?
O(n)

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3416099523852

Question
In algorithms, what is the big-O time complexity of merge sort?
O(nlogn)
^^ you are reducing the input size by half on each recursion cycle (so logn), and on each merge you are iterating through whole list (so n) so n*logn

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3416102669580

Question
In algorithms, what is the big-O time complexity of an algorithm that has nested loops (loop within a loop)?
O(n^2)

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3416105815308

Question
In algorithms, what is the big-O time complexity of an algorithm that has triple nested loop (loop in a loop in a loop)?
O(n^3)

status measured difficulty not learned 37% [default] 0

pdf

cannot see any pdfs

Flashcard 3419843202316

Question
In python 2, what is the easy way to sort a list, using "sorted" method, using a custom comparison function (for example, how to sort release_numbers = [1.2, 4.4.4, 1.2.1], using custom "compare" function that compares 1.2 to 1.2.1)?
sorted(release_numbers, cmp=compare)
^^ note the cmp arg is unique to python 2 and takes a custom compare function to use in sort.

status measured difficulty not learned 37% [default] 0

Flashcard 3419845823756

Question
In python 3, what is the easy way to sort a list, using "sorted" method, using a custom comparison function (for example, how to sort release_numbers = [1.2, 4.4.4, 1.2.1], using custom "compare" function that compares 1.2 to 1.2.1)?
sorted(release_numbers, key=functools.cmp_to_key(compare))
^^ note, in python 3, sorted does not have the cmp argument so you have to use the key argument via the functools.cmp_to_key conversion method)
^^ note 2, make sure you have "import functools" in your code

status measured difficulty not learned 37% [default] 0

Flashcard 3419848445196

Question
In python2, for the sorted and list.sort functions, what is the difference between the key argument vs the cmp argument?
key does a comparison against some derivitive of the list values being compared (e.g. len, for length) whereas cmp uses a custom functions to compare the whole of the two list items being compared (e.g. comparing release number 1.2 and 1.2.1 via a custom function)

status measured difficulty not learned 37% [default] 0

Flashcard 3419851066636

Question
In python, you have file called "test.txt", write code to print out all the lines from "test.txt" and use approach where you have to close the file handle explicitly.
f = open("test.txt")
for line in f:
print line
f.close()

status measured difficulty not learned 37% [default] 0

Flashcard 3419855260940

Question
In python, you have file called "test.txt", write code to print out all the lines from "test.txt" and use approach where you do not need to worry about closing file handles.
with open("test.txt") as f:
for line in f:
print line


status measured difficulty not learned 37% [default] 0

Flashcard 3419857882380

Question
In python, if you are at the REPL (python interactive shell), and you want to know more about a method (use "sorted" method as example) like its signiture, how do you get this info?
help(sorted)

status measured difficulty not learned 37% [default] 0

Flashcard 3419860503820

Question
In Linux, the keyboard shortcut for EOF (end of file), to exit the shell prompt for example (or exit the python REPL) is what?
ctrl-d

status measured difficulty not learned 37% [default] 0

Flashcard 3419864435980

Question
In Linux, what is the text editor that is the most common and available by default in all distros?
vi

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
an ordinary text file is known as text editing. A word processor is a kind of editor, but more basic than that is the UNIX or DOS text editor. 6.1 vi The important editor to learn how to use is <span>vi . After that you can read why, and a little more about other, more user-friendly editors. Type simply, vi <filename> to edit any file, or the compatible, but more advanced vim &lt

Flashcard 3419868105996

Question
In linux, what does the "m" in the "vim" text editor stand for?
vi "improved"

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
ow to use is vi . After that you can read why, and a little more about other, more user-friendly editors. Type simply, vi <filename> to edit any file, or the compatible, but more advanced <span>vim <filename> To exit vi , press , then the key sequence :q! and then press . vi has a short tutorial which should get you going in 20 minutes. If you get bored in the middle, you ca

Flashcard 3419871251724

Question
In Linux, the vi text editor has two modes, [...] mode and control mode
input

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
an read why, and a little more about other, more user-friendly editors. Type simply, vi <filename> to edit any file, or the compatible, but more advanced vim <filename> To exit vi , <span>press , then the key sequence :q! and then press . vi has a short tutorial which should get you going in 20 minutes. If you get bored in the middle, you can skip it and learn vi as you need t

Flashcard 3419874397452

Question
In Linux, the vi text editor has two modes, input mode and [...] mode
control

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
an read why, and a little more about other, more user-friendly editors. Type simply, vi <filename> to edit any file, or the compatible, but more advanced vim <filename> To exit vi , <span>press , then the key sequence :q! and then press . vi has a short tutorial which should get you going in 20 minutes. If you get bored in the middle, you can skip it and learn vi as you need t

Flashcard 3419877543180

Question
In Linux, for the vi editor, what key do you press to exit from control mode to input mode (and viceversa)?
ESC

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
a little more about other, more user-friendly editors. Type simply, vi <filename> to edit any file, or the compatible, but more advanced vim <filename> To exit vi , press , then the <span>key sequence :q! and then press . vi has a short tutorial which should get you going in 20 minutes. If you get bored in the middle, you can skip it and learn vi as you need to edit things.

Flashcard 3419880688908

Question
In python, for the vi editor, when in control mode, what do you type to force quit (quit without saving)?
:q!

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
about other, more user-friendly editors. Type simply, vi <filename> to edit any file, or the compatible, but more advanced vim <filename> To exit vi , press , then the key sequence <span>:q! and then press . vi has a short tutorial which should get you going in 20 minutes. If you get bored in the middle, you can skip it and learn vi as you need to edit things. To read the t

Flashcard 3419883834636

Question
In Linux, for the vi editor, if you are in control mode, how do you save and quit?
:wq

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
art insert mode. O Insert a blank line above the current line and then start insert mode. a Append (start insert mode after the current character). R Replace (start insert mode with overwrite). <span>:wq Save (write) and quit. :q Quit. :q! Quit forced (without checking whether a save is required). x Delete (delete under cursor and copy to register). X Backspace (delete left of cursor an

Flashcard 3419888291084

Question
In linux, what is the first line you use to start any shell script?
#!/bin/sh
^^ also accpetable: #!/bin/bash
^^ note there is no whitespace, and note that we are using the shebang (#!) syntax to indicate what program will be used to run the script (e.g. /bin/sh)

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
Edit the file using your favorite text editor. The first line should be as follows with no whitespace. [Whitespace are tabs and spaces, and in some contexts, newline (end of line) characters.] <span>#!/bin/sh The line dictates that the following program is a shell script, meaning that it accepts the same sort of commands that you have normally been typing at the prompt. Now enter a number of

Flashcard 3419891961100

Question
In Linux, what does the #! syntax do when you put it at the top of any type of script/code?
It tells linux what program to use (full path) to run the script (e.g. #!/bin/sh for shell script, #!/usr/bin/python3 for python, etc)

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
Edit the file using your favorite text editor. The first line should be as follows with no whitespace. [Whitespace are tabs and spaces, and in some contexts, newline (end of line) characters.] <span>#!/bin/sh The line dictates that the following program is a shell script, meaning that it accepts the same sort of commands that you have normally been typing at the prompt. Now enter a nu

Flashcard 3419895106828

Question
In Linux, in a shell script, how do you create a variable, x, and assign to it the value, 2?
x=2

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
keyboard into that pigeonhole. Thereafter, whenever the shell encounters NM , its contents are written out instead of the letters NM (provided you write a $in front of it). We say that NM is a <span>variable because its contents can vary. You can use shell scripts like a calculator. Try 5 echo "I will work out X*Y" echo "Enter X" read X echo "Enter Y" read Y echo "X*Y =$X*$Y =$[X*Y]" The

Flashcard 3419898252556

Question
In linux, you have a shell script with line "x=2", how do you print out the value of x
echo $x ^^ note the$ syntax does parameter/variable expansion, i.e. accesses the value of x, without it just "x" gets printed

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
, and then inserts text read from the keyboard into that pigeonhole. Thereafter, whenever the shell encounters NM , its contents are written out instead of the letters NM (provided you write a <span>$in front of it). We say that NM is a variable because its contents can vary. You can use shell scripts like a calculator. Try 5 echo "I will work out X*Y" echo "Enter X" read X echo "En Flashcard 3419902184716 Question In Linux, in shell scripts, the$[] syntax is called [...] [...]
expression expansion
^^ e.g. is: echo $[2*6], which would print "12" to the screen status measured difficulty not learned 37% [default] 0 7. Shell Scripting variable because its contents can vary. You can use shell scripts like a calculator. Try 5 echo "I will work out X*Y" echo "Enter X" read X echo "Enter Y" read Y echo "X*Y =$X*$Y =$[X*Y]" The <span>[ and ] mean that everything between must be evaluated [Substituted, worked out, or reduced to some simplified form. ] as a numerical expression [Sequence of numbers with + , - , * , etc. betwe

Flashcard 3419905330444

Question
In Linux, you have shell script, that has already defined x=2 and y=3, how do you print out the sum of x and y?
echo $[x+y] status measured difficulty not learned 37% [default] 0 7. Shell Scripting variable because its contents can vary. You can use shell scripts like a calculator. Try 5 echo "I will work out X*Y" echo "Enter X" read X echo "Enter Y" read Y echo "X*Y =$X*$Y =$[X*Y]" The <span>[ and ] mean that everything between must be evaluated [Substituted, worked out, or reduced to some simplified form. ] as a numerical expression [Sequence of numbers with + , - , * , etc. betwe

Flashcard 3419908476172

Question
In Linux, in shell scripting, the $syntax is called [...] [...] Answer variable expansion status measured difficulty not learned 37% [default] 0 7. Shell Scripting We say that NM is a variable because its contents can vary. You can use shell scripts like a calculator. Try 5 echo "I will work out X*Y" echo "Enter X" read X echo "Enter Y" read Y echo "X*Y = <span>$X*$Y =$[X*Y]" The [ and ] mean that everything between must be evaluated [Substituted, worked out, or reduced to some simplified form. ] as a numerical expression [Sequence of numbers w

Flashcard 3419911621900

Question
In linux, in shell scripting, the $() syntax (e.g.$(pwd) ), is called [...] [...]
command expansion

status measured difficulty not learned 37% [default] 0

Flashcard 3419914243340

Question
In Linux, in shell scripting, how do you print out the value of the pwd command (e.g. /home/kevin would be printed if you are in home directory)?