Solved

python, find first instance of a class

Posted on 2010-09-01
16
671 Views
Last Modified: 2012-05-10
I have finally managed to create a python class on my own - I've processed text into a list and then used the 'Words' class (see below) to access information from the list. But I can't find a way to grab the first instance of a given word length - the only thing I can do is this:

if length == 5:
    print all instances of words that contain 5 characters

but I want to print every unique instance of each word length instead.

When working with regular lists you can grab a minimum value, but I don't know how to specify a minimum return value for get_sequence() etc

Pls point me in the right direction thanks

class Words():
    def __init__( self, sequence, word, length):
        self.sequence = sequence
        self.word = word
        self.length = length

    def get_sequence( self ):
        return self.sequence

    def get_word( self ):
        return self.word

    def get_length( self ):
        return self.length

if __name__ == "__main__":
    our_words = []
    word_count('declaration.txt') #function omitted

    mots = []
    
    for sequence, word in enumerate( our_words ) :
        mots.append( Words( sequence, word, length=len(word)) )
           
    for i in range( len( mots ) ) :
        mot = mots[ i ]
        print '%d: %d %s: %d' % ( i, mot.get_sequence(), mot.get_word(), mot.get_length() )

Open in new window

0
Comment
Question by:sara_bellum
  • 9
  • 6
16 Comments
 
LVL 28

Expert Comment

by:pepr
ID: 33584229
If the Words class should work on the list of words, then I guess, the internal self.sequence should be the copy of the list.  Is it the intention?

Generally, a class defines (describes) behaviour of an object that (in programming) was created as the instance of the class.  The object has its interface (methods/functions to be called) and its internal data.  The member variables make sense only when they have to store some internal data.  With respect to this, I do not think you want to have self.word and self.length.  From your description, I guess you want to pass the word or length as argumets of methods.

The body of the script (below the if __name__) seems a bit confused to me.

If the class does not inherit from some other base class, it is usual not to use the empty parenthesis in "class Words():", i.e. only
"class Words:"

What should contain your variables sequence, word, length?  Can you show some example?
0
 
LVL 5

Expert Comment

by:-Richard-
ID: 33585867
More clarification is needed regarding what you are trying to accomplish.  Including the omitted function might be helpful.

A stylistic suggestion I would make is that the line
    for i in range( len( mots ) ) :
        mot = mots[ i ]
can be replaced by the simpler
    for mot in mots:
        ..........

However I don't have enough information to actually help you with your problem.
0
 

Author Comment

by:sara_bellum
ID: 33591365
I thought that by using a class, I could manipulate the data, but couldn't figure out how to extract the first instance of every word length from the data. So I created a python dictionary instead, see below.

The dictionary accomplishes what I'm trying to do, so I guess I'm still wondering if it's possible to do the same thing with a class definition and if so, how I might go about doing that.

Let me know thanks.


def mea_dict(our_words):

    ''' key = word length'''

    for i, word in enumerate(our_words):

        if len(word) not in dict_words:

            dict_words[len(word)] = {}

            dict_words[len(word)][word] = {}

            dict_words[len(word)][word] = i

    return dict_words



if __name__ == "__main__":

    our_words = []

    word_count('declaration.txt')

    dict_words = {}

    mea_dict(our_words)



    for key, value in dict_words.iteritems():

    print 'word length:', key, ', word and count:', value

Open in new window

0
 
LVL 28

Assisted Solution

by:pepr
pepr earned 500 total points
ID: 33591922
You think too hard about the "class".  It seems to me that you need to understand the basics first.

The "class" is a synonym for the "kind of".  The notion of a class and of an object is rather more abstract.  It is important to understand what is behind the terms.  And it is not that difficult.  You meet the same abstractions in everyday life.

Say the lentils (yes that kind of small seeds that can be eaten).  When you think about lentils, you think both in abstractions and in the real objects. If you want to describe lentils to someone who never saw it, you describe it in abstractions (small, round, and also flat, with brown or green skin, cookable, edible, etc.). When you want to eat, you need the tangible form of the lentils.  The description is the definition of what makes lentils different from anything else and what is the same when thinking about several instances (seeds) of the lentils. (Sorry for my English, if it is not that understandable.)

What was first.  Prehistoric people may have eaten lentils without neccessity to give it a name.  However, lentils early got its name because the people needed to share their experience.  

Nature does not need the classification, the description.  The things simply exist.  From that point of view, the description of that kind--the class--appeared after the instances.

Programming is a construction task. You have to have a blueprint first to build something.  The class (the description) must be designed first.  The instance is created based on that class.  Basically, an object (i.e. an instance of some class) is a memory space (i.e. tangible features) bound with the behaviour description.  The tangible part (the instance) of that couple stores the features and current state.  The abstract part (the class) describe the features and determines what is a lentil and what is already not.  The description separates artificially the Universe to lentils and the other things.

The Python dictionary can also be both the class and the object.  The class is static.  It cannot store anything.  It exists from the first definition until the environment for capturing the definition disappears. (Our brain is also such environment.  For us, the class exists until we forget it or until we disappear.)  The class of lentils existed even earlier than we invented the name.  Nature has its own blueprint -- DNA.

From that point of view, any Python class is a blueprint for the instances (objects) that are of the same type.  As a programmer, you should think about object as about tangible things.  You have to describe first their behaviour.  You must be sure what that tangible thing should represent and how it behaves towards the environment (towards the other objects).

The class describes, how the object should organize itself, how it should behave towards the other objects.  The Object Oriented Programming is based on idea of cooperation of objects.  It is a kind of modelling the reality.  The earlier approach--structured programming--was based around the notion of stateless function and activityless data.  The functions manipulated with data.

Still, the functions are not obsoleted by OO approach.  Sometimes you need a tool that is capable to manipulate with some tangible things -- with the objects.  This is also the case of your mea_dict() function.  It transforms the our_words to the outputed dictionary.

It is a design decision whether it is "more natural in this case" to have something that builds and transforms itself or whether it is better to have some outside tool to organize the things.
0
 
LVL 28

Accepted Solution

by:
pepr earned 500 total points
ID: 33592087
In your case, the core idea is to collect unique words of the same length.  In other words, you want to build sets of words.  Each set contains the words of the same length.  The second core idea is to collect somehow the sets to be able to access the right set quickly.  Here is what the code below prints:

c:\tmp\_Python\sara_bellum\Q_26446228>python a.py
['I', 'thought', 'that', 'by', 'using', 'a', 'class', 'I', 'could', 'manipulate'
, 'the', 'data', 'but', "couldn't", 'figure', 'out', 'how', 'to', 'extract', 'th
e', 'first', 'instance', 'of', 'every', 'word', 'length', 'from', 'the', 'data',
 'So', 'I', 'created', 'a', 'python', 'dictionary', 'instead', 'see', 'below', '
The', 'dictionary', 'accomplishes', 'what', "I'm", 'trying', 'to', 'do', 'so', '
I', 'guess', "I'm", 'still', 'wondering', 'if', "it's", 'possible', 'to', 'do',
'the', 'same', 'thing', 'with', 'a', 'class', 'definition', 'and', 'if', 'so', '
how', 'I', 'might', 'go', 'about', 'doing', 'that', 'Let', 'me', 'know', 'thanks
']
{1: set(['i', 'a']), 2: set(['me', 'do', 'of', 'to', 'so', 'go', 'by', 'if']), 3
: set(['and', 'but', 'how', 'see', 'let', 'the', "i'm", 'out']), 4: set(['what',
 'word', 'that', 'with', "it's", 'same', 'know', 'from', 'data']), 5: set(['gues
s', 'doing', 'could', 'about', 'thing', 'below', 'every', 'using', 'still', 'mig
ht', 'class', 'first']), 6: set(['python', 'length', 'trying', 'thanks', 'figure
']), 7: set(['thought', 'instead', 'extract', 'created']), 8: set(['instance', '
possible', "couldn't"]), 9: set(['wondering']), 10: set(['definition', 'dictiona
ry', 'manipulate']), 12: set(['accomplishes'])}

Length 1
---------------
   a
   i

Length 2
---------------
   by
   do
   go
   if
   me
   of
   so
   to

Length 3
---------------
   and
   but
   how
   i'm
   let
   out
   see
   the

Length 4
---------------
   data
   from
   it's
   know
   same
   that
   what
   with
   word

Length 5
---------------
   about
   below
   class
   could
   doing
   every
   first
   guess
   might
   still
   thing
   using

Length 6
---------------
   figure
   length
   python
   thanks
   trying

Length 7
---------------
   created
   extract
   instead
   thought

Length 8
---------------
   couldn't
   instance
   possible

Length 9
---------------
   wondering

Length 10
---------------
   definition
   dictionary
   manipulate

Length 12
---------------
   accomplishes
import re

def buildMyDict(words):
    d = {}   # init, empty dict
    for word in words:
        
        # The case of letters is not important to us. 
        word = word.lower()
        
        # Find the set for the len or create the empty one and get access to it.
        theSet = d.setdefault(len(word), set())  
        
        # Add the word to the set. It may have been there. Never mind. The set
        # stores it only once.
        theSet.add(word)
        
    return d  # the resulting dictionary of sets
     
     
if __name__ == '__main__':
     
    s = '''I thought that by using a class, I could manipulate the data, 
           but couldn't figure out how to extract the first instance of 
           every word length from the data. So I created a python dictionary 
           instead, see below.

           The dictionary accomplishes what I'm trying to do, so I guess I'm 
           still wondering if it's possible to do the same thing with a class 
           definition and if so, how I might go about doing that.

           Let me know thanks.'''
           
    rexWord = re.compile(r"[a-zA-Z']+")  # Let this describes words.
    our_words = rexWord.findall(s)
    print our_words                      # Just to see what we have.
    
    dd = buildMyDict(our_words)          # not a good name for the function...
    print dd                             # Just to see what we have.
    
    # Let pretty-print the result.
    for k in sorted(dd):    # a dictionary implicitly iterates through the keys
        print
        print 'Length', k
        print '---------------'
        for word in sorted(dd[k]):       # set converted to sorted list
            print '  ', word

Open in new window

0
 
LVL 28

Expert Comment

by:pepr
ID: 33592097
After understanding the above, we can return to the class design.  But you must make sure what the class should do for you, how the instances are to be used.
0
 

Author Comment

by:sara_bellum
ID: 33593968
Wow, I had no idea that you could create sets inside dictionaries, or that setdefault() even exists!! The same page in python docs contains another function I use a lot ( iteritems() ),  so I suppose I could have found this one too, but it certainly helps to see it in use -- thanks very much for that!

I'm afraid that your English is much stronger than my understanding of python classes, or how to build them : (  I'm still confused by how to write functions inside a class (versus outside a class).  When I call a function and get a traceback error, I usually understand the error, unless it's part of a class. This is logical because I don't understand how to write functions inside classes - they look very different to me!

I think an instance is what happens when a function is called. When a function that belongs to a class is called, then the class should be part of the call or there will be a 'method undefined' error. And of course the function should return a value or an object. So in that regard methods work the same whether or not they're in a class. That's how much I understand, and not much else.

If I could see how to achieve the same output as above with a class, it would make classes easier for me to understand I think.

0
 
LVL 28

Assisted Solution

by:pepr
pepr earned 500 total points
ID: 33595054
For iteritems(): The method is specific to dictionaries.  My opinion is that it is rarely used.  You may often want to iterate through all dictionary items; however, it is enough to get the keys.  The .iteritems() returns tuples (key, value).  Another reason to be lazy to use the .iteritems() is that you can simply use the dictionary in the for loop -- without any specific method called.  It will iterate through the elements of the dictionary and it will give you the keys.  Simply said, do not use .iteritems() // unless you are 100 % sure what you are doing.

The class/object methods are nothing more than functions that know their own object.  The static attribute of the object is the internal data.  The dynamic attribute of the object is that the data is changed via its methods.  The methods simply know what data are to be changed.

It may be clearer when you think about the pre-OOP era.  The function gets  the block of data, and possibly some arguments, manipulates the passed block of data, and possibly returns some value.  In OOP, the block of data becomes the data part of the object, the related function becomes the method of the object. The function is still a function, but it is used only with the specific data (but it can be passed some arguments).

Now the key for understanding the difference.  If obj is the pre-OOP object (i.e. the block of data), and the oldfunction is the pre-OOP function, then you call it:

retval = oldfunction(obj, arg1, arg2)

When the obj was created as instance of theClass and theMethod is a member function of theClass, you can also call it in Python the similar way as earlier:

retval = theMethod(obj, arg1, arg2)   # syntax error because...

But because theMethod is the member of the class, it is hidden iside the class and it cannot be called without telling Python that it is from inside theClass.  The class creates also the namespace with the same name (as also module does -- the name of the file without .py).
Thus, you can write:

retval = theClass.theMethod(obj, arg1, arg2}    # this is OK

Actually, there is one more limitation.  The obj must be of the same type (i.e. of the same class -- theClass).  In other words, it must be the instance of theClass.

The instance of a class is create when you use the name of the class as if it was a function.  It looks as if you "called the class".  The parentheses are neccessary here:

obj = theClass()

There is one syntax enhancement that is related to the fact that both the data part and the methods belong to the class. This way, you can use the obj as the prefix of the method call, separated by dot. The obj knows its class and the call can be (as if) transformed to the above form:

retval = obj.theMethod(arg1, arg2)

You can think about moving the obj from the first positional argument to the front of theMethod.

This also explains why methods are written in Python the way they are written.  When the class is defined, you do it technically.  The self is the actual argument and you use it in the body this way.  The self is the name of the object as seen from inside.

Continue with your questions ;)
class theClass:
    def theMethod(self, arg1, arg2):
         return arg1 + arg2

obj = theClass()

retval = theClass.theMethod(obj, 1, 2)
print retval

retval = obj.theMethod(1, 2)
print retval

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Expert Comment

by:pepr
ID: 33595138
Concerning a set() [notice here that the 'set' is the name of the class and 'set()' returns the just created instance of the class] inside a dictionary: Any container object (which is the list, dictionary, set, your own containing classes, ...) in Python can store object of any type as the value.  The reason is that Python uses "untyped references" and the type is bound to the object (unlike in usual compiled languages).  Python does not care what kind of object is assigned.  Python does not deep-copy the value of the object.  It simply copies the (untyped) reference to the object.  The dictionary contains only the references.  The real objects are "outside".

Similarly, the keys of a dictionary can be of any type but with some limitations.  The main limitation is that the key value must never change for the existing element.  This means that the key object must be immutable.  It also must possible to compute the hash value of the key object (see the hash() built-in function and the .__hash__() special object method).  Putting it together, the hash value of the key must be constant.
0
 

Author Comment

by:sara_bellum
ID: 33601479
ok, progress is being made :)

I've managed to print two columns of key - value pairs by calling a function directly (which returns the correct values) and by calling it from a class (which does not). I copy the code below, with my comments / questions, using the object names from your previous post to minimize confusion.

I still find the application of theory to practice confusing but expect that I will learn with experience. It makes sense that numbers 1 - 15 (all available word lengths in the Declaration of Independence that I'm using as my text file input) show up as words and skew the length of the first two sets when I call the return value of the class: I had to convert these integers to strings in order to get the function to work as written (because I didn't know how else to change it).

I don't understand why this happens to get_set() inside the class, but not when the same function is declared outside the class - it should be written in different ways for these two situations I expect.


def learn(declaration):



    for word in declaration:

        word = word.lower()

        setNumber = dict_sets.setdefault(len(word),  set())

        setNumber.add(word)



    return dict_sets



class Words:



    def __init__( self, dict_sets):

        self.dict_sets = dict_sets



    def get_set( self, declaration ):

        for word in declaration:

            #word = word.lower() #int object has no attribute lower

            #print word #word = integers 1 - 15 (why?)

            word = str(word)

            setNumber = dict_sets.setdefault(len(word),  set())

            setNumber.add(word)



        return self.dict_sets



if __name__ == "__main__":

    declaration = []

    word_count('declaration.txt')

    dict_sets = {}

    learn(declaration)

    #print(dict_sets)# dict output looks good

    word_sets = learn(declaration)

    print 'Length' , '   Word Count'

    for k in sorted(word_sets):

        print ' ' * 2, k, ' ' * 7, len(sorted(word_sets[k]))

    print '\n', '#'*25, '\n'



# now try with class:



    obj = Words(dict_sets)

    #retval = Words.get_set(dict_sets) #unbound method get_set() must be called with Words instance (why?)

    retval = obj.get_set(dict_sets)

    #print retval # prints dict object, but with numbers 1 - 15

    print 'Length' , '   Word Count'

    for k in retval:

        print ' ' * 2, k, ' ' * 7, len(retval[k])

Open in new window

0
 

Author Comment

by:sara_bellum
ID: 33604323
Ok I fixed it and copy the whole thing below. I still do not know why the set numbers are excluded when defining only the function, but when the function is declared as part of a class, the set numbers are included in the sets. But I'm sure this will become clear in due course : )
def word_count(my_file):
    punctuation = [',', '.', ';', ':', '"']
    source = open('declaration.txt', 'r').readlines()
    for line in source:
        line = line.strip()
        if line == '':
            continue
        for phrase in line.split(', '):
            word_list = phrase.split(' ')
            for word in word_list:
                for x in punctuation:
                    if x in word:
                        word = word[:-1]
                if '--' in word:
                    word = word[2:]
                declaration.append(word)
    return declaration

def learn(declaration):
    
    for word in declaration:
        word = word.lower()
        setNumber = dict_sets.setdefault(len(word),  set())  
        setNumber.add(word)
        
    return dict_sets

class Words:

    def __init__( self, dict_sets):
        self.dict_sets = dict_sets

    def get_set( self, declaration ):
        for word in declaration:
            if word not in range( 1, 16 ):
                setNumber = dict_sets.setdefault((word),  set())
                setNumber.add(word)

        return self.dict_sets

if __name__ == "__main__":
    declaration = []
    word_count('declaration.txt')
    dict_sets = {}
    learn(declaration)
    word_sets = learn(declaration)
    print 'Length' , '   Word Count'
    for k in sorted(word_sets):
        print ' ' * 2, k, ' ' * 7, len(sorted(word_sets[k]))
    print 

# now try with class:

    obj = Words(dict_sets)
    retval1 = Words.get_set(obj,dict_sets)  
#corrected: retval = theClass.theMethod(obj, 1, 2)
    retval = obj.get_set(dict_sets)
    print 'Length' , '   Word Count'
    for k in retval:
        if k < 10:
            print ' ' * 2, k, ' ' * 7,  len(retval[k]) 
        else:
            print ' ', k, ' ' * 7,  len(retval[k])

Open in new window

0
 
LVL 28

Assisted Solution

by:pepr
pepr earned 500 total points
ID: 33604654
Firstly, the word_count.  You do use too many loops inside.  I do understand your way of thinking; however, unneccessary nested loops almost always lead to inefficiency.  Also, you have to name all characters that are not considered part of the word -- this may be exhaustive.

There are some bugs.  You pass the name of the file (bad identifier), but you do something else in open().  Fortunately, it is the same that you passed; however, it will not work for another file.

If str.strip(arg) argument contains more characters, then this arg string is the exact separator.  On your line 8, comma at the end of line would not be recognized.

Lines 12 and 13:  x in word is true also when x is in the middle of characters.  But you throw away always the last character (it could be something else than x).  The same holds for 14 and 15.

You return the list of words.  Instead, you wanted to return its lenght.  See below the word_count() implemented differently.  Ask for details.
import re

def word_count(filename, rexWord=re.compile(r'[a-zA-Z]+')):
    # Here the words are defined by the regular expression (ask if in doubt).
    f = open(filename)  # (do make distinction between filename and file object)
    content = f.read()  # content of the file read at once
    f.close()           # file should be closed explicitly
    declaration = rexWord.findall(content)  # get the list of all words 
    print declaration   # this is the list (just to see)
    return len(declaration)  # this is the wanted count

if __name__ == "__main__":
    print word_count('declaration.txt')

Open in new window

0
 
LVL 28

Assisted Solution

by:pepr
pepr earned 500 total points
ID: 33604701
With the class and learn...  Whenever you want to use the member of the object inside the object method, you have to prefix it self.  Have a look at the code below, try it and ask what is not clear.  The wordLst should probably also be the method of the class -- later.
import re

def wordLst(filename, rexWord=re.compile(r'[^\s,.;:"-]+')):
    f = open(filename)
    content = f.read()
    f.close()
    return rexWord.findall(content)


class Words:

    def __init__(self):
        self.dict_sets = {}      # init -- no word yet

    def learn(self, declaration):
        for word in declaration:
            if 1 < len(word) < 16:  # only the words with certain length
                setNumber = self.dict_sets.setdefault(len(word),  set())
                setNumber.add(word)

    def pretty_print(self):
        print 'Length', '   Word Count'
        for k in self.dict_sets:
            print '%2d       %4d' % (k, len(self.dict_sets[k]))
      

if __name__ == "__main__":
    words = Words()    # empty, but could be combined with the next
    words.learn(wordLst('declaration.txt'))
    words.pretty_print()

Open in new window

0
 

Author Comment

by:sara_bellum
ID: 33623671
Yes, one step at a time :)

I think the wordLst calls the regular expression (re) module to compile a list of punctuation marks found at the end of any string, plus the apostrophe (not always at the end); and that findall is a function of the re module that is applied to the content / f.read() method.

I edited the pretty_print function to print key / value pairs horizontally and then as a histogram and copy my code below ... I'm still confused about string formatting but I'm getting there and hope to be very close to finishing this up, thanks very much!!
class Words:



    #your solutions omitted, my changes to pretty_print() follow



    def print_output(self):

        out.write('\n\n' + '#' * 35 + ' Keys and Values ' + '#'*35 + '\n \n')

        # print the word count values

        out.write( 'Word Count :' )

        for k in self.dict_sets:

            out.write('%2d  %s' % (len(self.dict_sets[k] ), ' '))

        # print the word length keys

        out.write('\nWord Length:' )

        for k in self.dict_sets:

            out.write( '%2d %s ' % (k , ' ' ))



        # Now try this as a histogram

        out.write('\n\n' + '#' * 35 + ' HISTOGRAM ' + '#'*42 + '\n \n')

        out.write('Word' + ' '*51 + 'Word\n')

        out.write('Length' + ' '*49 + 'Count\n')

        for k in self.dict_sets:

            out.write( '%2d ' % k )

            for x in range( 10 ):

                if x < len(self.dict_sets[k]):

                    x = '+'

                else:

                    x = '-'

                out.write('%s' % ('    ' + x))

            out.write('%4s %2d' % ( ' ' , len(self.dict_sets[k] ) ) + '\n' )



if __name__ == "__main__":

    # your solutions omitted

    out = open('numbers.txt',  'w')

Open in new window

0
 
LVL 28

Assisted Solution

by:pepr
pepr earned 500 total points
ID: 33624542
Important design thing -- the out should be the argument of your print_output(), i.e.:

    def print_output(self, out):
        ...

This way you do not need to touch the body of the method.  You only have to pass the out explicitly when calling the method.  The reason why it is important is that then the class does not depend on the outer code.  You can also pass whatever object that supports the .write() method, and the class will work with it just fine (i.e. not only another file object, but also what is sometimes called file-like object or stream object).

For the formatting.  It is similar to other programming languages that allow using a format string -- the string with placeholder marks.  There are two main ways used these days and both are supported by Python (the newer one only by Python 2.6 and newer, I believe).  The older approach is related to the C language and (in principle) even back to Fortran and probably to some older languages.  It is sometimes called "string interpolation" as the values are converted to the strings.

The older way used '%x' as placeholders where x is certain character that describes the type of the passed value.  The format string is used with the % (another % char, unrelated to placehodler in some sense) and with the tuple of values (or with a single value) like :   'format %d %x %s'  %  (5, 50, 'text')  
See http://docs.python.org/release/2.6.6/library/stdtypes.html#string-formatting-operations for details.

The new way uses different syntax for placeholders.  I saw it first time in C# but I do not know where it came from.  It uses curly braces with something inside (nothing, number, ... plus other options) -- see http://docs.python.org/library/string.html#format-examples for Python 2.6 and newer. The format string is considered an object (it really is an objec) and its method .format(arg1, arg2, ...) is used to describe the arguments that are to be placed instead of the placeholders.
0
 

Author Closing Comment

by:sara_bellum
ID: 33633200
Ok I cleaned up my string formatting, working in python 2.5 since that's what I have at work.  No sense in dragging this out - this works for now and I'm very grateful for all the help!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sum28 challenge 31 96
constructor while deserilizing object 16 53
countHi challenge 25 86
wordcount challenge 11 78
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now