Py Modules Flashcards

1
Q

How to import a module?

A

> > Import

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name 4 useful modules?

A

collections ( counter ), random, math, webbrowser

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can a random integer be created?

A
]] from random  import seed
]] from random  import random
]] seed(  )
]] print( random(), random() )
]]0.7215400323407826 0.22876222127045265 

– the function random will consistently generate the same random numbers every time

https://machinelearningmastery.com/how-to-generate-random-numbers-in-python/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Dict, what’s the difference between a dictionary and a list?

A

Dictionary store key, value pairs, whereas lists are a range of values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you find out if an object is a dictionary or not?

A

.type( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you express a dictionary’s structure?

A

{ key:value, key:value }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Do you know of any rules for dictionary’s keys?

A

Immutable, can’t be a list for the key but can be used for the value, not ordered

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to add a single new value to a dictionary?

A

]] [ ‘key’ ] = ‘value’

]] t1_dict[ ‘abc’ ] = 99

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to see all pairs in a dictionary?

A

]] < dict_name >
or
]] < dict_name >.items( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

1) How to see all keys in dictionary?

2) How to see all values for a dictionary?

A

]] .keys( )

]] .values( ) `

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Value in Dict or List, how to check if a specific value is in a dict or a list?

– ERROR: needs to be updated –

A

]] if in

– recturns True or False

– WRONG –

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Value in Dict, how to fetch a specific value from a Dict?

A

]] .get( ‘key’ )

    • returns pair’s value
    • changed from True or False
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to compare two textstrings similiarity?

A

]] import difflib
]] difflib.get_close_matches( ‘word_to_compare’, [ ‘words’, ‘‘in, ‘‘list, ‘to’, ‘compare’, ‘against’], 1, 0.6 )

    • 1: how many words to return as a close match
    • 2: ratio to be fulfilled for the words to return
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how to find the ratio of similarity between two textstrings?

A

]] difflib.SequenceMatcher( None, ‘word_comp_1’, ‘word_comp_2’).ratio()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how to see all installed modules?

A

]] help( ‘modules’ )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly