[Tutor] Do something on list elements

2018-07-27 Thread Valerio Pachera
Hi all, I started studying python and I hope you may help me getting better. Let's start with the first question. Consider this example --- #!/usr/bin/python3 l = ['unoX', 'dueX'] c = 0 for n in l: l[c] = l[c].replace('X','') c = c + 1 print (l) --- it works but I wonder if ther

Re: [Tutor] Do something on list elements

2018-07-30 Thread Valerio Pachera
- Messaggio originale - > Da: "Tutor Python" > A: "Tutor Python" > Inviato: Sabato, 28 luglio 2018 0:06:55 > Oggetto: Re: [Tutor] Do something on list elements > But better still is a list comprehension: > > l = [s.replace('X','') for s in l) > print(l) Thank you all for the answers. L

[Tutor] Dictionary viceversa

2018-07-30 Thread Valerio Pachera
Hi all, consider this dictionary users = {'user1':['office-a', 'office-b'], 'user2':['office-b'], 'user3':['office-a','office-c']} It's a list of users. For each user there's a list of room it can access to. Generalizing, a dictionary with a list for each element. d = {k:list} I wi

[Tutor] Remove soft line break

2019-02-04 Thread Valerio Pachera
I have a file with row that split at the 80th character. The next row start with a blank space, meaning that i part of the previous row. Example: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non justo enim. Viv amus dapibus quis neque vitae ornare. Pellentesque at pharetra sapi

Re: [Tutor] Remove soft line break

2019-02-28 Thread Valerio Pachera
- Messaggio originale - > Da: "Valerio Pachera" > A: "Tutor Python" > Inviato: Giovedì, 28 febbraio 2019 13:05:27 > Oggetto: Re: [Tutor] Remove soft line break >... > It works as expected but there's a thing I've to understand about the

Re: [Tutor] Remove soft line break

2019-02-28 Thread Valerio Pachera
e - Da: "Peter Otten" <__pete...@web.de> A: "Tutor Python" Inviato: Lunedì, 4 febbraio 2019 20:23:59 Oggetto: Re: [Tutor] Remove soft line break Valerio Pachera wrote: > > I have a file with row that split at the 80th character. > The next row start with a blank

Re: [Tutor] Remove soft line break

2019-03-16 Thread Valerio Pachera
- Messaggio originale - > Da: "Valerio Pachera" > A: "Tutor Python" > Inviato: Giovedì, 28 febbraio 2019 13:05:27 > Oggetto: Re: [Tutor] Remove soft line break > ... > I noticed that the end of file doesn't get preserve if I create a

[Tutor] Merge a dictionary into a string

2019-03-16 Thread Valerio Pachera
Consider this: import collections d = OrderedDict(a='hallo', b='world') I wish to get a single string like this: 'a "hallo" b "world"' Notice I wish the double quote to be part of the string. In other words I want to wrap the value of a and b. I was thinking to use such function I created: de