git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New to python - Just a question


On 2020-07-03 10:09, Daley Okuwa via Python-list wrote:
> Write an algorithm (choose the language you prefer) that given a
> character string,?for instance {?c?,?a?,?i?,?o?,?p?,?a?}, will
> print out the list of characters appearing at least 2 times.?In
> this specific example, it would return {?a?}. Afterwards, comment
> out the cost in terms of space and time.

What have you tried already?  Where are you having trouble?

Have you written a program that accepts a character string?  Is the
string coming in as a command-line argument or on standard-input?

The example string you give looks more like some sort of
serialization format rather than a string.

Are you having difficulty counting the letters?  Python provides a
"dict()" type that would work well.

Should uppercase letters be counted the same as lowercase letters?
I.e., should "Pop" report that there are 2 "p"s?

If you've counted the duplicates, 

Have you studied space/time complexity and do you know how to
evaluate code for these characteristics?  The problem should be
solvable in roughly O(k) per word.

> Write a bash/python script that takes a directory as an argument
> and output the total lines of code in *.cpp files recursively.

Again, what have you tried?

Have you been able to iterated over a directory? See find(1) or ls(1)
or grep(1) in a shell-script or os.listdir()/os.scandir()/glob.glob()
in Python

Have you been able to open those files?

Can you iterate over the lines in each file?

Do you need to filter out any lines (such as blank lines or comments)?

If you provide what you've tried, folks here on the list are pretty
happy to help.  But most won't do your homework for you.

-tkc