Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Zadaci za wannabe pythoniste

[es] :: Python :: Zadaci za wannabe pythoniste

Strane: << < .. 19 20 21 22 23 24 25 26 27 28 ... Dalje > >>

[ Pregleda: 52223 | Odgovora: 629 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste06.04.2020. u 16:43 - pre 49 meseci
A ne, ispisujem sva imena, nema nikakve obrade. To je namerno.
 
Odgovor na temu

a1234567

Član broj: 46801
Poruke: 297
136.228.174.*



+3 Profil

icon Re: Zadaci za wannabe pythoniste11.04.2020. u 17:38 - pre 49 meseci
Stiže zadatak 33.
Kopiram iz knjige, da ne prevodim...

Spell Checker
A spell checker can be a helpful tool for people who struggle to spell words correctly.
In this exercise, you will write a program that reads a file and displays all of the words
in it that are misspelled. Misspelled words will be identified by checking each word
in the file against a list of known words. Any words in the user’s file that do not
appear in the list of known words will be reported as spelling mistakes.

The user will provide the name of the file to check for spelling mistakes as a
command line argument. Your program should display an appropriate error message
if the command line argument is missing. An error message should also be displayed
if your program is unable to open the user’s file. Make solution to this exercise
so that words followed by a comma, period or other punctuation mark are not reported
as spelling mistakes. Ignore the capitalization of the words when checking their spelling.

Hint: While you could load all of the English words from the words data set
into a list, searching a list is slow if you use Python’s in operator. It is much
faster to check if a key is present in a dictionary, or if a value is present in a
set. If you use a dictionary, the words will be the keys. The values can be the
integer 0 (or any other value) because the values will never be used.


 
Odgovor na temu

a1234567

Član broj: 46801
Poruke: 297
136.228.174.*



+3 Profil

icon Re: Zadaci za wannabe pythoniste11.04.2020. u 17:40 - pre 49 meseci
Ovako nešto sa pokušao:
Code:
import argparse
import re
import string
import sys

wordlist_recnik = {}

# Otvori listu engleskih reči u odnosu na koje će dati tekst biti proveravan.
# Napravi rečnik u kojem je svaka od reči key. Value je 0, jer nikada neće biti korišćeno.

with open('c:/FAJLOVI/Python_School/Stephenson_ThePythonWorkbook/wordlist.txt', "r", encoding='utf-8') as recnik:
    reci = recnik.readlines()
    reci[:] = [line.rstrip('\n') for line in reci]
    for rec in reci:
        wordlist_recnik[rec] = 0

greske = []

# Provera da su dati svi argumenti.
if len(sys.argv) != 2:
    print("Unesi ime fajla za slovnu analizu. Npr. >> 167.py fajl.txt")
    quit()
    
try:
    with open(sys.argv[1], 'r', encoding='utf-8') as tekst:
        text = tekst.read()
except:
    print("Dogodila se greška pri učitavanju fajla.")
    quit()

print(text)

def words(text):
    samo_reci = re.sub(r'[^\w\s]','',text)
    lista = samo_reci.lower().split()
    for word in lista:
        if word not in wordlist_recnik:
            greske.append(word)
    print()
    print('Ovo su reči koje treba popraviti:')
    print(*greske, sep='\n')
    return
words(text)
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste11.04.2020. u 17:46 - pre 49 meseci
Citat:
a1234567:
Stiže zadatak 33.
Kopiram iz knjige, da ne prevodim...

Spell Checker
A spell checker can be a helpful tool for people who struggle to spell words correctly.
In this exercise, you will write a program that reads a file and displays all of the words
in it that are misspelled. Misspelled words will be identified by checking each word
in the file against a list of known words. Any words in the user’s file that do not
appear in the list of known words will be reported as spelling mistakes.

The user will provide the name of the file to check for spelling mistakes as a
command line argument. Your program should display an appropriate error message
if the command line argument is missing. An error message should also be displayed
if your program is unable to open the user’s file. Make solution to this exercise
so that words followed by a comma, period or other punctuation mark are not reported
as spelling mistakes. Ignore the capitalization of the words when checking their spelling.

Hint: While you could load all of the English words from the words data set
into a list, searching a list is slow if you use Python’s in operator. It is much
faster to check if a key is present in a dictionary, or if a value is present in a
set. If you use a dictionary, the words will be the keys. The values can be the
integer 0 (or any other value) because the values will never be used.




Mozda bi bilo bolje da se zada i 33', tj za ulaznu rec naci najblize korektne alternative.
To ako hoces da trazis posao u guglu :P

 
Odgovor na temu

a1234567

Član broj: 46801
Poruke: 297
136.228.174.*



+3 Profil

icon Re: Zadaci za wannabe pythoniste11.04.2020. u 17:54 - pre 49 meseci
Zvali su me, al sam im rekao da nemam vremena.
Učim python na elite forumu
 
Odgovor na temu

a1234567

Član broj: 46801
Poruke: 297
136.228.174.*



+3 Profil

icon Re: Zadaci za wannabe pythoniste12.04.2020. u 04:15 - pre 49 meseci
Jedno pitanjce.
Nešto sam eksperimentisao, pa mi nije jasan rezultat.

Code:
x = ['Ovo ', 'je', ' test']

for i in x:
    if i[0] or i[-1] == ' ':
        print(i)

Ovo
je
test


Kako to da se 'je' nalazi u ispisu kad nema razmak!?
 
Odgovor na temu

Panta_
Aleksandar Pantić
Kragujevac

Član broj: 214959
Poruke: 790



+162 Profil

icon Re: Zadaci za wannabe pythoniste12.04.2020. u 05:14 - pre 49 meseci
Zato što ne proverava da li ima razmak, treba:

Code:
if i[0] == ' ' or i[-1] == ' '

ili

if ' ' in i
 
Odgovor na temu

a1234567

Član broj: 46801
Poruke: 297
136.228.174.*



+3 Profil

icon Re: Zadaci za wannabe pythoniste12.04.2020. u 07:55 - pre 49 meseci
Aha, mora odvojeno. Dobro.
A ja hteo da se ugledam na tebe, pa da sve smlatim ujedno, kad ono neće moći :)))
 
Odgovor na temu

Panta_
Aleksandar Pantić
Kragujevac

Član broj: 214959
Poruke: 790



+162 Profil

icon Re: Zadaci za wannabe pythoniste12.04.2020. u 08:23 - pre 49 meseci
Evo jedan zanimljiv zadatak dok ste u izolaciji.

Na https://github.com/CSSEGISandD...ta/csse_covid_19_daily_reports
imate dnevne izveštaje u CSV formatu sa podacima o korona virus slučajevima (država, potvrđeni, umrli, oporavljeni, itd.).

E sad, treba preuzeti sve te podatke i smestiti ih u fajl npr. corona_data.json:

Code:

{
    "04-12-2020": [
        {
            "FIPS": "",
            "Admin2": "",
            "Province_State": "",
            "Country_Region": "Serbia",
            "Last_Update": "2020-04-11 22:45:13",
            "Lat": "44.0165",
            "Long_": "21.0059",
            "Confirmed": "3380",
            "Deaths": "74",
            "Recovered": "0",
            "Active": "3306",
            "Combined_Key": "Serbia"
        },
        itd...
    ], itd...
}


Dalje, napisati program koji podrazumevano (ako je pokrenut bez argumenata)
ispisuje podatke sortirane po broju potvrđenih slučajeva od najvišeg, na primer:

Code:

Country     Confirmed     Deaths     Recovered

US          526396      20463   31270
itd...
Serbia      3380        74      0


Zatim, ako je npr. unet argument top, program ispisuje 10 država sa najviše
potvrdjenih slučajeva, a pored toga i broj novih slučaja, ili npr. top deaths
sa najviše umrlih:

Code:

Top 10 Deaths:

Country  Deaths  New Deaths

US       20463   2125
Italy    19468   619
itd...

Top 10 Recovered:

Country     Recovered     New Recovered

China         77877         86
Spain         59109         3441
itd...


Dalje, dopuniti program po svom izboru, na primer pored navedenih podataka,
ispisati vreme kada su poslednji put ažurirani ili geografske kordinate,
ukupan broj potvrdjenih, umrlih i oporavljenih, ako je kao argument unet datum,
ispisati samo podatke za isti, itd.

Malo opširniji zadatak, ali eto da se zanimate dok ste u izolaciji.
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste12.04.2020. u 23:35 - pre 49 meseci
Jedino sad ne bih smestao u json, posto je taj format za transfer preko neta, tj serijalizaciju. Nego bolje u bazu, bar po meni.
(import iz csv-a je standardna stvar za baze)
Zgodno je sto je git repo pa moze da se svuce i apdejtuje prostim git komandama :P
 
Odgovor na temu

Panta_
Aleksandar Pantić
Kragujevac

Član broj: 214959
Poruke: 790



+162 Profil

icon Re: Zadaci za wannabe pythoniste13.04.2020. u 05:25 - pre 49 meseci
Citat:
Nego bolje u bazu, bar po meni.

Da, ali onda i korisnik mora da je ima instaliranu. Ovako je u pitanju običan fajl. Python podrazumevano ima podršku za json i csv, kao i urllib.request modul da se preuzmu potrebni podaci (da ne mora Git da se instalira). Mislim da i Rust ima navedeno, ili pak može da se instalira preko Cargo paket menadžera.
Ako mora baza, onda preporuka za Sqlite.
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste13.04.2020. u 05:38 - pre 49 meseci
" ili pak može da se instalira preko Cargo paket menadžera."

Da, mora da se napravi projekt, tj Cargo.toml i da se izlistaju dependency-ji/
Nista strasno, cim nadjem vremena uradicu. Inace vec sam sve svukao u postgres :P
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste15.04.2020. u 15:10 - pre 49 meseci
Heh, lakse je sa git, ovako prvo moras da formiras url tj prvo da povuces preko github apija listu fajlova, parsujes json, pa onda iz liste da vuces fajl parsujes json pa base64 decode
i tek onda dobijas csv content, pa onda parsuj csv content i stavljaj u json :P
Sva sreca da za sve postoje biblioteke :P
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste15.04.2020. u 18:29 - pre 49 meseci
Bad news za korisnike api-ja:


Code:

{"message":"API rate limit exceeded for 109.72.51.23. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://developer.github.com/v3/#rate-limiting"}


Nije ni pola fajlova skinulo...
 
Odgovor na temu

Panta_
Aleksandar Pantić
Kragujevac

Član broj: 214959
Poruke: 790



+162 Profil

icon Re: Zadaci za wannabe pythoniste15.04.2020. u 21:03 - pre 49 meseci
Ja nisam koristio api, već sam povadio linkove do csv fajlova.

Code:

from urllib.error import URLError
from urllib.request import Request, urlopen
import re

req = Request('https://github.com/CSSEGISandD...ta/csse_covid_19_daily_reports')
    try:
        with urlopen(req) as response:
            html = response.read().decode('utf-8')
    except URLError as e:
        print(e.reason)
        raise

links = re.findall('CSSEGISandData/COVID-19/blob/master/csse_covid_19_data/csse_covid_19_daily_reports.*\.csv(?=\")', html)

 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste15.04.2020. u 21:47 - pre 49 meseci
Da, a kako ces da dodjes do csv fajlova? Problem je kada pocnes da skidas...
Inace otparsovao sam csv ostalo je smestanje u json, a tu je naravno i problem struktuiranja
podataka jer nisu svi fajlovi sa istim headerima...
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste16.04.2020. u 04:51 - pre 49 meseci
https://github.com/bmaxa/covid19report

Ovo je za import u json, ostaje prikaz :P

Program ce pokusavati sve dok ne upise i poslednji fajl. Limit je 60 reqs/sat

edit:
bilda se sa `cargo build --release` kada se udje u dir

 
Odgovor na temu

Panta_
Aleksandar Pantić
Kragujevac

Član broj: 214959
Poruke: 790



+162 Profil

icon Re: Zadaci za wannabe pythoniste16.04.2020. u 05:55 - pre 49 meseci
Citat:
Da, a kako ces da dodjes do csv fajlova? Problem je kada pocnes da skidas...

Kreiram url od csv linkova i preuzimam ih na isti gore navedeni način, zatim čitam sa csv reader, itd..
Citat:
tu je naravno i problem struktuiranja podataka jer nisu svi fajlovi sa istim headerima

Da, to sam tek kasnije video da su izmenili. Takođe, treba voditi računa da su za pojedine države (USA, Kina, itd.) dati podaci pojedinačno za svaku državu, odnosno provinciju.
 
Odgovor na temu

Branimir Maksimovic

Član broj: 64947
Poruke: 5534
109.72.51.23



+1064 Profil

icon Re: Zadaci za wannabe pythoniste16.04.2020. u 06:11 - pre 49 meseci
"Kreiram url od csv linkova i preuzimam ih na isti gore navedeni način, zatim čitam sa csv reader, itd.."

kako kada dobijas html, a ne csv?
 
Odgovor na temu

Panta_
Aleksandar Pantić
Kragujevac

Član broj: 214959
Poruke: 790



+162 Profil

icon Re: Zadaci za wannabe pythoniste16.04.2020. u 06:17 - pre 49 meseci
Citat:
bilda se sa `cargo build --release` kada se udje u dir

Neće:
Code:
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> src/main.rs:1:1
  |
1 | #![feature(try_blocks)]
  | ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
error: could not compile `covid19report`.


A, evo i razlog:
Code:
rustc --explain E0554

Feature attributes are only allowed on the nightly release channel. Stable or
beta compilers will not comply.

Example of erroneous code (on a stable compiler):

```
#![feature(non_ascii_idents)] // error: `#![feature]` may not be used on the
                              //        stable release channel
```

If you need the feature, make sure to use a nightly release of the compiler
(but be warned that the feature may be removed or altered in the future).


Probao sam sa rustup install nightly, ali opet ista greška.
 
Odgovor na temu

[es] :: Python :: Zadaci za wannabe pythoniste

Strane: << < .. 19 20 21 22 23 24 25 26 27 28 ... Dalje > >>

[ Pregleda: 52223 | Odgovora: 629 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.