From Python to Rust. Part 3: A Dictionary and a HashMap.

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 10

  • @luzyoz143
    @luzyoz143 3 года назад +4

    this was so great! I have been putting off learning Rust because I don't have a whole lot of C/C++ experience but this really gave me the confidence to dive in, thanks! please keep this going, would love to work along the rest of the algorithms.

  • @__wouks__
    @__wouks__ 2 года назад +2

    I am busy learning Rust coming from Python and I really like these videos.
    Just one note though. You indicated on line 9 of the Python code that the if test_dict['Key_3'] checks if the string of 'Key_3' is within the dictionary. This actually just retrieves the underlying value which in this case is a list. And because the list has values it is considered truthy which is why it works here. To look whether a key is in a dictionary you can either use a try except and catch the key error or in this scenario I would use the in keyword.
    So you would have to write if 'Key_3' in test_dict

  • @erik-martin
    @erik-martin 3 года назад +1

    These videos are under viewed. Appreciated what you did in this short series.

  • @nazarkostetskiy4822
    @nazarkostetskiy4822 2 года назад +1

    Thanks. Only one thing that I really don't like in rust hashmaps: their syntax. Declaration and dict manipulation are more pure in python, js, dart, go and it's really not presentable to interact with dict in rust way.

  • @RagHelen
    @RagHelen 4 года назад +2

    Please go on with this series.

  • @climatechangedoesntbargain9140
    @climatechangedoesntbargain9140 3 года назад +1

    You could use a enum to either store only one string or a vector of strings

  • @evalinor
    @evalinor 2 года назад

    vscode theme name pls

  • @danyalziakhan
    @danyalziakhan 3 года назад

    In case someone is having the problems compiling the code: (as of writing this):
    ```rand::thread_rng().gen_range``` takes one argument, so it will be ```rand::thread_rng().gen_range(0..nucleuotides.len())```
    HashMap needs to be imported, so write ```use std::collections::HashMap;``` on top of the file.

    • @climatechangedoesntbargain9140
      @climatechangedoesntbargain9140 3 года назад

      Seems like you forgot the "use.." statement at the top? 😉

    • @danyalziakhan
      @danyalziakhan 3 года назад +1

      @@climatechangedoesntbargain9140 Really? I think it's present in my comment.