baavgai's Profile User Rating: *****

Reputation: 5988 Overlord
Active Posts:
12,980 (4.87 per day)
16-October 07
Profile Views:
Last Active:
User is offline Today, 03:46 AM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Your Car:
Who Cares
Dream Kudos:
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: count vowels in word/sentence

    Posted 1 Feb 2015

    It's a good program.

    I'd put the user prompt below, next to the call. I'd also consider breaking up the count and the show.

    def countVowels(word):
        vowelList ={'a': 0, 'e' : 0,
            'i': 0, 'o' : 0,
            'u' : 0}
        for letter in word:
            if vowelList.has_key(letter):
                vowelList[letter] += 1
        return vowelList
    def showCount(d):
        for e in d:
            print e, d[e]
    def askUser():
        print("Enter a word or sentence to count the vowels from")
        return raw_input()
    worder = askUser()
    count = countVowels(worder)

    As I was formatting this, I notice semicolons; get rid of them. Python likes the four char indent, but not required.

    And, what the hell, from the skinning cats different department:
    def countVowels(word):
        vowels = "aeiou"
        xs = [ vowels.find(x) for x in word.lower() ]
        return dict((v,sum(1 for x in xs if x==i)) for (i,v) in enumerate(vowels))

    You'll occasionally see "There should be one-- and preferably only one --obvious way to do it." It's a cute thought, but for programming in general it's more wishful thinking than reality.

    Keep up the good work.
  2. In Topic: Count occurrences in a list

    Posted 31 Jan 2015

    For the output, I'd try something like:
    def countOccurrences(xs):
        d = {}
        for i in xs:
            if i not in d: d[i] = 1
        print("\n".join("{0} occurs {1} times".format(k,v) for (k,v) in sorted(d.items())))

    Note that it's also sorted, making for easier reading.
  3. In Topic: Displaying an image from xml feed

    Posted 31 Jan 2015

    View Posthm9, on 31 January 2015 - 06:27 PM, said:

    thats very simple response and already know about it! the question is how to change or modify the code to make it work with javascript code i posted.

    So... let me get this straight.

    You know how to do this:

    And you know how to do this:
    <img src="your url here" />

    But this is beyond you?!?
    document.write("<td><img src='");

    Sorry, it looks like you don't understand what you claim to. You might wish to brush up on what you think you know.

    As a side note, using document.write is about a decade out of favor. Brush up on DOM methods as well.
  4. In Topic: Displaying an image from xml feed

    Posted 31 Jan 2015

    For web dev, before you learn Javascript, you want to learn HTML...

    An image tag would simply be:
    <img src="your url here" />
  5. In Topic: sort an array into a second array

    Posted 31 Jan 2015

    Since you essentially have been given the solution, I'll throw a couple more at you.

    First, with the smallest thing:
    class lab {
        public static void main(String args[]) {
            //Code enclosed I cannot change//
            int ar[] = {7, 5, 2, 8, 4, 9, 6};
            int sorted[] = new int[ar.length];
            int smallest = 100000;
            int indexsmallest = 0;
            //Code enclosed I cannot change//
            // note, smallest = 100000 is pointless and bad design
            // actually, declaring all the variables up there is also poor design
            smallest = ar[0]; // first one is smallest until prove otherwise
            for (int i = 1; i < ar.length; i++) {
                if (ar[i] < smallest) {
                    smallest = ar[i];
            // now that you have your first smallest, pop it in
            sorted[0] = smallest;
            // note, you could have used sorted[0] for all of the above
            // and ignored smallest
            // we already have the first one, so start at one again
            for (int i = 1; i < ar.length; i++) {
                // here is where setting smallest to some stupid large
                // number might help
                smallest = 100000;
                // now, find the smallest number > the last smallest number
                for (int j = 0; j < ar.length; j++) {
                    if (ar[j] < smallest && ar[j] > sorted[i - 1]) {
                        // note the ar[j] > sorted[i-1]
                        // see, we want the smallest after the last smallest
                        smallest = ar[j];
                sorted[i] = smallest;
            System.out.println("smallest number " + sorted[0]);
            //Code below I cannot Change//
            for (int i = 0; i < sorted.length; i++) {
                System.out.println("sorted[" + i + "] = " + sorted[i]);

    Hmm... I see I didn't use indexsmallest. Also, the code will fail if there are duplicates. I'm afraid I don't respect the smallest thing.

    What I'd do, ultimately given a requirement of using a destination array for the sorted data:
    class lab {
        public static void main(String args[]) {
            //Code enclosed I cannot change
            int ar[] = {7, 5, 2, 8, 4, 9, 6};
            int sorted[] = new int[ar.length];
            int smallest = 100000;
            int indexsmallest = 0;
            //Code enclosed I cannot change
            // we're going to iterate through all elements of ar
            for (int i = 0; i < ar.length; i++) {
                // we're going to push that value into the end of
                // our sorted array
                sorted[i] = ar[i];
                // then, we're going to "bubble" it up to it's proper position
                for (int j = i; j > 0; j--) {
                    // check if the one below is in the right place
                    // if it is, stop
                    if (sorted[j - 1] < sorted[j]) { break; }
                    // otherwise, swap
                    int temp = sorted[j];
                    sorted[j] = sorted[j - 1];
                    sorted[j - 1] = temp;
            // that's it
            // the above is an insertion sort
            // one of the basic sorts you should be learning
            // you'd normally do it in place
            // here, we're building that other array, but same idea
            // I don't know wtf the smallest thing is about
            System.out.println("smallest number " + sorted[0]);
            //Code below I cannot Change
            for (int i = 0; i < sorted.length; i++) {
                System.out.println("sorted[" + i + "] = " + sorted[i]);

    Please, please, please, don't just plug this stuff into your assignment and turn it in. Look at it. Try to figure out what it's doing. Understand the steps that are being taken. Put a ton of print statements in there is you're confused about anything, to show you what's going on.

    Hope this helps.

My Information

Member Title:
Dreaming Coder
Age Unknown
Birthday Unknown
Jersey, be afraid.
Years Programming:
Programming Languages:

Contact Information

Click here to e-mail me
Website URL:
Website URL  http://


  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  2. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  3. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address ( I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  4. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  5. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  6. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  7. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  8. Photo Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
  9. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
  10. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  11. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  12. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  13. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  14. Photo

    hulla Icon

    02 Aug 2011 - 02:50
    Wow that's alot of programming languages... :O
  15. Photo

    Aphex19 Icon

    04 Jul 2011 - 16:54
    Kudos to you baavgai, the most well deserved mentor on DIC in my opinion.
  • (3 Pages)
  • +
  • 1
  • 2
  • 3