Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 629 odgovora
  • 108.675 pregleda

Najnovija ↓

Re: Zadaci za wannabe pythoniste 11.04.2020. u 18:38 · pre 79 meseci #462
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.


Re: Zadaci za wannabe pythoniste 11.04.2020. u 18:40 · pre 79 meseci #463
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)
Re: Zadaci za wannabe pythoniste 11.04.2020. u 18:46 · pre 79 meseci #464
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

Re: Zadaci za wannabe pythoniste 12.04.2020. u 05:15 · pre 79 meseci #466
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!?
Re: Zadaci za wannabe pythoniste 12.04.2020. u 06:14 · pre 79 meseci #467
Zato što ne proverava da li ima razmak, treba:

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

ili

if ' ' in i
Re: Zadaci za wannabe pythoniste 12.04.2020. u 08:55 · pre 79 meseci #468
Aha, mora odvojeno. Dobro.
A ja hteo da se ugledam na tebe, pa da sve smlatim ujedno, kad ono neće moći :)))
Re: Zadaci za wannabe pythoniste 12.04.2020. u 09:23 · pre 79 meseci #469
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.
Re: Zadaci za wannabe pythoniste 13.04.2020. u 00:35 · pre 79 meseci #470
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
Re: Zadaci za wannabe pythoniste 13.04.2020. u 06:25 · pre 79 meseci #471
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.
Re: Zadaci za wannabe pythoniste 13.04.2020. u 06:38 · pre 79 meseci #472
" 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
Re: Zadaci za wannabe pythoniste 15.04.2020. u 16:10 · pre 79 meseci #473
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
Re: Zadaci za wannabe pythoniste 15.04.2020. u 19:29 · pre 79 meseci #474
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...
Re: Zadaci za wannabe pythoniste 15.04.2020. u 22:03 · pre 79 meseci #475
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)

Re: Zadaci za wannabe pythoniste 15.04.2020. u 22:47 · pre 79 meseci #476
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...
Re: Zadaci za wannabe pythoniste 16.04.2020. u 06:55 · pre 79 meseci #478
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.
Re: Zadaci za wannabe pythoniste 16.04.2020. u 07:11 · pre 79 meseci #479
"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?
Re: Zadaci za wannabe pythoniste 16.04.2020. u 07:17 · pre 79 meseci #480
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.
Odgovori
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme