Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Salve, vorrei scrivere un piccolo script che, dati in input una serie di stringhe nella forma "4f 6a 23 d9 10" di lunghezza arbitraria, restituisca un'unica stringa in formato "\0x1a\0xa1\0x92\...", ottenuta anteponendo "\0x" ad'ogni coppia di cifre separata da spazio, per ogni stringa immessa .
Io mi stavo approcciando cosi:
Per risolvere il problema, ti sarà utile utilizzare la finzione split().
Dalla documentazione ufficiale:
Codice sorgente - presumibilmente Python
str.split([sep[, maxsplit]])
Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit isnot specified or -1, then there is no limit on the number of splits (all possible splits are made).
If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (for example, '1,,2'.split(',') returns ['1', '', '2']). The sep argument may consist of multiple characters (for example, '1<>2<>3'.split('<>') returns ['1', '2', '3']). Splitting an empty stringwith a specified separator returns [''].
If sep isnot specified orisNone, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty stringor a string consisting of just whitespace with a None separator returns [].