Notes in Python - Pythonic

To Subscribe, use this Key


Status Last Update Fields
Published 05/03/2024 Combine a sequence with another:a = [11, 45, 19]b = [22, 37]
Published 05/03/2024 round() can take 1 or 2 parameters. Explain.n = 2.39393
Published 05/03/2024 What is returned by the following code: range(3,7)
Published 05/03/2024 What function is used to convert to string?3.393
Published 05/03/2024 Create a single string separated by commas.a = ['a','c','d','b']
Published 05/03/2024 How to get the absolute value of a number?n = -3.93
Published 05/03/2024 How to floor a floating point number?n = 3.29393
Published 05/03/2024 How to iterate through the key value pairs of a dictionary?colors = {'blue':(0,0,255), 'red':(255,0,0)}
Published 05/03/2024 Given a sequence how to get the following:the length of the sequencethe largest elementthe smallest elements = [12, 13, 10, 9]
Published 05/03/2024 Slice the first two elements from a sequence.l = ['a','c','d','b']
Published 05/03/2024 How to return the last element of a sequence?s =  [12, 23, 19, 45]
Published 05/03/2024 How to slice the last two elements from a sequence?s = [12, 23, 19, 45]
Published 05/03/2024 How to slice all elements from a sequence except the first and last?l = [12, - 23, -55, -88, -19, 45]
Published 05/03/2024 What slice notation would return the entire sequence?l = [12, 23, 19, 45]
Published 05/03/2024 How to slice the odd subscripted elements of a sequence?s = [13, 43, 29, 11, 99, 37, 55, 17]
Published 05/03/2024 s = [13, 43, 29, 11, 99, 37, 55, 17]Get every third element
Published 05/03/2024 How to sort a list in ascending order?s = [13, 43, 29, 11, 99, 37, 55, 17]
Published 05/03/2024 How to test that if particular value is in or not in a sequence?s  = [11, 45, 19, 22, 37]
Published 05/03/2024 Make 3 copies of the elements in a sequence and concatenate them.s = [11, 45, 19, 22, 37]
Published 05/03/2024 How to slice all but the last two elements from a sequence? l = ['a','b','c','d','e']
Published 05/03/2024 Given some sequence S:What is the difference between S.pop(), S.pop(0) and S.pop(-1) and what sequence types can pop be used with?
Published 05/03/2024 How to insert an element at the beginning of the sequence?l = [3, 9, 5]item = 7
Published 05/03/2024 Add 4 to end of the sequence.s = [1,2,3]
Published 05/03/2024 What is the best way to iterate through the elements of a sequence if you need access to the subscripts as you go?name = 'brett'
Published 05/03/2024 Print a count down from 3?
Published 05/03/2024 Create a string consisting of fifty '-' characters?
Published 05/03/2024 How to count the occurences of a "tw" within a string?s = 'two twits twittered twenty tweets'
Published 05/03/2024 How to get the index of the first occurence of a substring within a string?s = 'i like eggs but eggs are high in cholesterol''eggs''celery'
Published 05/03/2024 How to split a string into tokens using the character ',' as a delimeter?s = 'al,fl,tn,ga,sc,ms'
Published 05/03/2024 Given a list of elements:s = [13, 43, 99, 20, 45]How to rearrange the elements of the list in random order?
Published 05/03/2024 How to randomly choose one element from the sequence?s = [13, 43, 99, 20, 45]
Published 05/03/2024 Remove the whitespace from both sides of the string?s = '         brett     &nbs…
Published 05/03/2024 Given two variables, x and y:What is the simplest way to swap the value of these two variables (one line)?x = 5y = 9
Published 05/03/2024 Name 2 ways to reverse the order of the elements of this list?l =  [10, 44, 29, 30, 12, 99]
Published 05/03/2024 Ccreate a sublist consisting of the elements of a list wich are evenly divisible by 6? l = [4, 6, 18, 32, 24, 20, 42, 16, 54, 96, 112]1. Use…
Published 05/03/2024 Define 3 variables, x, y and z and initialize them to zero (one line).
Published 05/03/2024 Perform floored division on 8 by 5
Published 05/03/2024 How to compute 2 to the 5th power?
Published 05/03/2024 Assign a = 1, b = 2, c = 3.Use unpacking.
Published 05/03/2024 for ... :else:
Published 05/03/2024 Exception Coding
Published 05/03/2024 Create a string representation of an object. Name 2 ways.l = ['a', 'c', 'd', 'b']
Published 05/03/2024 recursion
Published 05/03/2024 Make each world title case. Use map.s = ['hi', 'there']
Published 05/03/2024 Polymorphism
Published 05/03/2024 Modify the list so that the first letter of each word is capitalized(title case) for each string in the list.Use map.names = ['leonhard euler', 'paul …
Published 05/03/2024 LEGB Rule
Published 05/03/2024 Create a list adds 10 to each value 0:5.Use list comprehension.
Published 05/03/2024 %d
Published 05/03/2024 %s
Published 05/03/2024 reset
Published 05/03/2024 pandas
Published 05/03/2024 L = [3,2,1,0]L.index(1)
Published 05/03/2024 Count number of "1"sl = [3,2,1,0,1,2,3]
Published 05/03/2024 L = [3,2,1,0,1,2,3]L.remove(2)
Published 05/03/2024 l = [_**2 for _ in range(5)]
Published 05/03/2024 apply ord function to each element of spam
Published 05/03/2024 help(str.split)
Published 05/03/2024 find is a string method.What is the similar method for lists?
Published 05/03/2024 Convert string litteral to ASCII code. Use map.s = 'spam'
Published 05/03/2024 create arg variable and pass in to range function 
Published 05/03/2024 check for s object in global variables
Published 05/03/2024 Find square root of 16
Published 05/03/2024 Create list of 6 random numbers between 1 and 10
Published 05/03/2024 Compare two numbersx = 1y = 2
Published 05/03/2024 Get last word in a strings = "I like eggs."
Published 05/03/2024 Interate and print contents of winewines = {2011:'White', 2009:'Red'}
Published 05/03/2024 find current working directory
Published 05/03/2024 automaically change working directory to directory were script is
Published 05/03/2024 Everything in Python is an ______
Published 05/03/2024 Everything in Python can grouped in a ____.
Published 05/03/2024 r"hello\n world"
Published 05/03/2024 Create a generator object with indexes and go through first 2 itemscolors = ['blue', 'red', 'green']
Published 05/03/2024 Find the current version of numpy
Published 05/03/2024 Returns True when an argument is true,False otherwise. eg: 0>1
Published 05/03/2024 reload module/file named temp.py
Published 05/03/2024 define n as a fraction,14/3
Published 05/03/2024 repr
Published 05/03/2024 bytearray
Published 05/03/2024 one liner: remove whitespace & commasreturn lista = 'aaa, bbb, ccccc, dd     '
Published 05/03/2024 __foo__
Published 05/03/2024 r'C:\text\new'
Published 05/03/2024 calculate execution time
Published 05/03/2024 What is __init__.py used for?
Published 05/03/2024 When is pass used for?
Published 05/03/2024 What is a docstring?
Published 05/03/2024 Given the list below remove the repetition of an element.All the elements should be unique:words = ['one', 'one', 'two', 'three', 'three', 'two']
Published 05/03/2024 Remove the whitespaces from the string.s = 'aaa bbb ccc ddd eee'1) Use split and join2) Use filter
Published 05/03/2024 sorted() is a _________
Published 05/03/2024 Sort the list below based on lower case values:s = ['This', 'is', 'a', 'test', 'string', 'from', 'Andrew']
Published 05/03/2024 Get last record from the following list:student_info = [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]
Published 05/03/2024 Sort the following list by age:student_info = [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]
Published 05/03/2024 Create a Student Class that has name, grade, and age. Create one instance of a student.
Published 05/03/2024 __str__
Published 05/03/2024 __repr__
Published 05/03/2024 Find time of function.range(100)
Published 05/03/2024 Create a generator expression for squares.
Published 05/03/2024 Loop through in reverse alphabetical order
Published 05/03/2024 Sort by length of wordcolors = ['red', 'green', 'blue', 'yellow']
Published 05/03/2024 Create an iterable object from 1 to 10
Published 05/03/2024 Interate through keys in dictionaryd = {'matthew': 'blue', 'rachel': 'green', 'raymond': 'red'}
Published 05/03/2024 Remove all key/value pairs that have keys that starts with r.d = {'matthew': 'blue', 'rachel': 'green', 'raymond': 'red'} #=> {…
Published 05/03/2024 Create a dictionary where keys are index values and values are names.names = ['matthew', 'rachel', 'raymond']
Published 05/03/2024 Create a set of ASCII codes for 'spaaaam'1) use set comprehsion2) use set function (hint: use map function also)
Published 05/03/2024 A set is like dictionary but ____
Published 05/03/2024 Create a dictionary of letters and ASCII codes'spaaaaam'
Published 05/03/2024 Get sorted list of keysd = { 'c': 3, 'a': 1, 'd':4, 'b': 2}
Published 05/03/2024 Find intersection using operatorx = set('spam')y = set('ham')
Published 05/03/2024 Find unionX = set('spam')Y = set('ham')
Published 05/03/2024 Find differenceX = set('spam')Y = set('ham')
Published 05/03/2024 {n ** 2 for n in [1, 2, 3, 4]}
Published 05/03/2024 'spam''asmp'Order-neutral equality
Published 05/03/2024 make d a decimal type
Published 05/03/2024 Create y as placeholder variable.
Published 05/03/2024 Test if l is a list using type label.l = [1,2,3]
Published 05/03/2024 Test for list type using object oriented function calll = [1,2,3]
Published 05/03/2024 Create an one liner that checks if apple, returns 'yes' or 'no'fruit = 'orange'
Published 05/03/2024 Get result if you multiply every element in a list from 1 to 10 using for loop.
Published 05/03/2024 What is virtualenv?
Published 05/03/2024 Where would you use tuples over lists?
Published 05/03/2024 What are decorators and what is their usage?
Published 05/03/2024 Shuffle list in placewords = ["python", "java", "constant", "immutable"]
Published 05/03/2024 Shuffle list of wordswords = ["python", "java", "constant", "immutable"]
Published 05/03/2024 Print pi to 2 places to the right of decimal point using string formating.
Published 05/03/2024 Test if l is a list using type definition.l = [1,2,3]
Published 05/03/2024 Multiply every element in a list from 1 to 10 by 10.Use a map expression.
Published 05/03/2024 reduce()
Published 05/03/2024 Do mutable objects such as lists, sets, and other dictionaries work as keys?
Published 05/03/2024 Create a list 'l' out of a dictionary.t = {1975: 'Holy Grail', 1979: 'Life of Brian', 1983: 'HolyGrail'}
Published 05/03/2024 Get value for (2, 3, 6) key in dict M. Return 'missing key' if key is not present.Use a dict method.M = {(2,3,6):99}
Published 05/03/2024 What are the 2 types of arguments for a function?
Published 05/03/2024 How do you check if all values in an iterable are true?
Published 05/03/2024 get max of 80, 100, 1000
Published 05/03/2024 Objects written to files have to be ____.
Published 05/03/2024 all()
Published 05/03/2024 get pwd from shell(from script)
Published 05/03/2024 run python file from ipython
Published 05/03/2024 check for presence of key in list comprehension
Published 05/03/2024 from collections import defaultdict
Published 05/03/2024 frozenset
Published 05/03/2024 import pylab
Published 05/03/2024 test is string is a numbers= "1234"
Published 05/03/2024 assign 'a = 0' using metaprogramming
Published 05/03/2024 ignore zeros
Published 05/03/2024 time something
Published 05/03/2024 import cProfile
Published 05/03/2024 get information about methods on vv = ["it's full of stars", 'elderberries', 4, 3, 3, 2]
Published 05/03/2024 turn mylist into dictionarymy_list = [("cat","dog"), ("one",1),("two",2)]
Published 05/03/2024 system call for ls
Published 05/03/2024 decorator
Published 05/03/2024 generator
Published 05/03/2024 Create variable a-d and assign them to 1-4 respectively.
Published 05/03/2024 Use Augmented Assignments to get reminder of x divided by yx = 6y = 5
Published 05/03/2024 name a variable that will NOT be imported with from module
Published 05/03/2024 Name 3 ways to multiple each element in y by 2y = [1, 2, 3]
Published 05/03/2024 write string to file
Published 05/03/2024 write a function that checks if a fruit is a apple return True or False
Published 05/03/2024 Do a case type function with:d = {'spam': 1.25, 'ham': 1.99, 'eggs': 0.99, 'bacon': 1.10}choice = 'ham'
Published 05/03/2024 get with error handlingd = {'spam': 1.25, 'ham': 1.99, 'eggs': 0.99, 'bacon': 1.10}
Published 05/03/2024 if x is true then a equals y, else a equals zx = [2] # True | Falsey, z = 100000, -999
Published 05/03/2024 Refactor to one-linerif x:   a = yelse:    a = zGiven:x = Truey, z = 100000, -999
Published 05/03/2024 Loop through and print each pair of tuplest = [(1, 2), (3, 4), (5, 6)]
Published 05/03/2024 map takes which 2 arguments ______ & _______
Published 05/03/2024 test if object s is a strings = "1234"
Published 05/03/2024 import 3.4 printing
Published 05/03/2024 Create a dog class:shares kind = 'canine'creates unique
Published 05/03/2024 What is class variable?
Published 05/03/2024 What is operator overloading?
Published 05/03/2024 from UserDict import UserDictclass FileInfo(UserDict):    pass
Published 05/03/2024 What is the most base object in Python?
Published 05/03/2024 square each number from 1 to 10use map
Published 05/03/2024 What is the general format for list comprehensions? 
Published 05/03/2024 Create all possible combinations of given lists using list comprehsions[1, 2, 3][100, 200, 300]
Published 05/03/2024 What are generator functions?
Published 05/03/2024 What are generator expressions?
Published 05/03/2024 What does yield do?
Published 05/03/2024 Give generator function below, create an instance.def gensquares(N):    for i in range(N):        yield i ** 2
Published 05/03/2024 Create a generator expression for squares of numbers
Published 05/03/2024 Force generator to produce all resultsG = (c * 4 for c in 'SPAM')
Published 05/03/2024 Create an interable object for given dictionaryd = {'a':1, 'b':2, 'c':3}
Published 05/03/2024 filter out all the elements of a listthat are mod 2 fib = [0,1,1,2,3,5,8,13,21,34,55]
Published 05/03/2024 Calculate the sum of the numbers from 1 to 100 using reduce
Published 05/03/2024 create a variable x is equal to 10 and print it interpreter
Published 05/03/2024 Refactor to be split on to 2 linesprint("Hello " + "World!")
Published 05/03/2024 Unpack data but throw away shares and pricedata = [ 'ACME', 50, 91.1, (2012, 12, 21) ]# name, shares, price, date = data
Published 05/03/2024 Unpack each character into its own variables = 'Hello'
Published 05/03/2024 create a deque with maxium length 3
Published 05/03/2024 Find 3 largest number in numsn = [1, 8, 2, 23, 7, -4, 18, 23, 42, 37, 2]
Published 05/03/2024 Create an ordered dictionary(('foo',1), ('bar',2), ('spam',3), ('grok',4))
Published 05/03/2024 get hash id y = "Hello, world!"
Published 05/03/2024 Create pairs of tuples for the give lists:l = [1,2,3,4] m = [5,6,7,8]
Published 05/03/2024 Zip list togethera = 'abc'z = 'xyz123'
Published 05/03/2024 Zip list together, pad extra spots with Nonea = 'abc'z = 'xyz1'
Published 05/03/2024 Create an interator that counts down from 150 to 125.
Published 05/03/2024 Create a struct-like object using namedtuple that has field1, field2
Published 05/03/2024 Create a class (AB) that has two simple places for variables (a, b)
Published 05/03/2024 A generator looks like a _____ but behaves like a ______.
Published 05/03/2024 create a queue from 0 to 5
Published 05/03/2024 Enumerate a list in reversea = ["foo", "bar", "baz"]
Published 05/03/2024 Write a list comprehsion that replaces zeros with 2a = [0,1,0,3]
Status Last Update Fields