Ad
Code
Diff
  • # ojeriejire rust version in python
    def split(string, separator):
        split_list = []
        i = 0
        
        for j, c in enumerate(string):
            if c == separator:
                slice_ = string[i:j]
                split_list.append(slice_)
                i = j + 1
        
        split_list.append(string[i:])
        return split_list
    
    
    • fn split(string: &str, separator: char) -> Vec<&str> {
    • let mut split = Vec::new();
    • let mut i = 0;
    • # ojeriejire rust version in python
    • def split(string, separator):
    • split_list = []
    • i = 0
    • for (j, c) in string.char_indices() {
    • if c == separator {
    • let slice = &string[i..j];
    • split.push(slice);
    • i = j + 1;
    • }
    • }
    • for j, c in enumerate(string):
    • if c == separator:
    • slice_ = string[i:j]
    • split_list.append(slice_)
    • i = j + 1
    • split.push(&string[i..]);
    • return split;
    • }
    • split_list.append(string[i:])
    • return split_list