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

C# to Python conversion

[es] :: Python :: C# to Python conversion

[ Pregleda: 4928 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

wraith46

Član broj: 336363
Poruke: 29



+1 Profil

icon C# to Python conversion13.04.2017. u 16:13 - pre 84 meseci
Imam dve male metode napisane u C# koje treba da konvertujem u Python.

Code:

void Remove()
{
    Word word = new Word();
    try { word = FindWord(listView1.SelectedItems[0].Text); }
    catch { return; }
    if (listView1.SelectedItems.Count > 0)
    {
        try
        {
            foreach (ListViewItem eachItem in listView1.SelectedItems)
            {
                words.RemoveAll(x => x.WordOrPhrase == eachItem.Text);
                listView1.Items[listView1.Items.Count - 1].Selected = true;
                listView1.Items.Remove(eachItem);
            }
        }
        catch { }
        ClearAll();
        ReadOnlyON();
    }
    else
    {
        MessageBox.Show("You have not selected any words!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    ReadOnlyOFF();
    WordCount();
    Sync();
}

private Word FindWord(string word)
{
    return words.Find(x => x.WordOrPhrase == word);
}


Evo sta sam uradio dosad:

Code:
def FindWord(word):
    for x in words:
        if x.WordOrPhrase == word:
            return x


Code:
def FindWord(word):
    return next((x for x in words if x.WordOrPhrase == word), None)


Code:
def FindWord(word):
    return next(filter(lambda x: x.WordOrPhrase == word, words), None)


Mucim se sa Remove() metodom:

Code:
def remove_item(self):

    word = Word()

    try:
        word = find_word(self.listBox.get(ACTIVE))
    except:
        return

    if self.listBox.get(ACTIVE) > 0:
        try:
            for item in self.listBox.get(ACTIVE):
                self.words.remove(lambda x: x.wordorphrase == item.text)
                self.listBox # listView1.Items[listView1.Items.Count - 1].Selected = true;
                self.listBox.remove(item)
        except:
            pass
        self.clear_all()

    else:
        pass
        # show messagebox



[Ovu poruku je menjao wraith46 dana 13.04.2017. u 19:36 GMT+1]
 
Odgovor na temu

[es] :: Python :: C# to Python conversion

[ Pregleda: 4928 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

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