[PIPython] confronto tra liste

tiziano a work tiziano
Ven 19 Nov 2004 15:16:51 CET


sicuramente è più "stilisticamente corretto" del mio codice offuscato...

;-)

ciccio a unical.it wrote:

>for i in lista1: 
>        for k in lista2: 
>                if i.strip().find(k.strip())!=-1: 
>                        idx=lista1.index(i) 
>                        lista1[idx]=i.strip()+"\t"+((k.strip()).split("\t") 
>[3]+"\n" 
> 
>Non so se stilisticamente corretto ma ho pensato di ricercare la sottostringa 
>ed eventualmente sostiture l'elemento che la contiene con quello aggiornato in 
>lista1. Se si stampa la nuova lista1 gli elementi sono come me li aspettavo  
> 
>  
>
>> 
>>dummy = [ s for s, x in [(j,j.find(i)) for i in lista2 for j in lista1]  
>>if x != -1] 
>>for s in lista1: 
>>     if s in dummy: 
>>             print s + "stringa fissa" 
>>     else: 
>>             print s 
>> 
>> 
>> 
>>estrae da lista1 le stringhe che hanno in lista2 una sottostringa 
>> 
>>ciccio a unical.it wrote: 
>> 
>>    
>>
>>>Sono due liste di stringe. La lista1 e' lunga 100 mentre la lista2 10. Le  
>>>stringhe della lista2 sono sottostringhe della lista1. Vorrei:  
>>> 
>>>per ogni stringa in lista1:  
>>>	se la stringa in lista2 e' una sua sottostringa:  
>>>		stampa stringa in lista1+"stringa costante"  
>>>	altrimenti:  
>>>		stampa solo la stringa in lista1  
>>> 
>>>Non so come iterare sulle due liste, perche' se uso   
>>> 
>>>for i in lista1:  
>>>	for k in lista2:  
>>>		etc..  
>>>funziona ma mi stampa per ogni valore di i i 10 valori di k (lista2)  
>>> 
>>>   
>>> 
>>>  
>>>
>>>      
>>>
>>>> 
>>>>cioé?  
>>>> 
>>>>cosa vorresti confrontare di preciso?  
>>>> 
>>>> 
>>>>ciccio a unical.it wrote:  
>>>> 
>>>>    
>>>>
>>>>        
>>>>
>>>>> 
>>>>>Per caso sapreste indicarmi come confrontare elementi di liste di  
>>>>>      
>>>>>
>>>>>          
>>>>>
>>>differenti  
>>>  
>>>
>>>      
>>>
>>>> 
>>>>    
>>>>
>>>>        
>>>>
>>>>>lunghezze?   
>>>>> 
>>>>>grazie    
>>>>>ernesto   
>>>>>
>>>>>-------------------------------------------------  
>>>>>This mail sent through IMP: http://horde.org/imp/  
>>>>>
>>>>>_______________________________________________  
>>>>>Python mailing list  
>>>>>Python a lists.python.it  
>>>>>http://lists.zope.it/cgi-bin/mailman/listinfo/python  
>>>>>
>>>>>  
>>>>>
>>>>>      
>>>>>
>>>>>          
>>>>>
>>>> 
>>>>_______________________________________________  
>>>>Python mailing list  
>>>>Python a lists.python.it  
>>>>http://lists.zope.it/cgi-bin/mailman/listinfo/python  
>>>> 
>>>>    
>>>>
>>>>        
>>>>
>>> 
>>> 
>>>
>>>------------------------------------------------- 
>>>This mail sent through IMP: http://horde.org/imp/ 
>>>
>>>_______________________________________________ 
>>>Python mailing list 
>>>Python a lists.python.it 
>>>http://lists.zope.it/cgi-bin/mailman/listinfo/python 
>>>
>>>  
>>>
>>>      
>>>
>> 
>>_______________________________________________ 
>>Python mailing list 
>>Python a lists.python.it 
>>http://lists.zope.it/cgi-bin/mailman/listinfo/python 
>> 
>>    
>>
> 
> 
>
>-------------------------------------------------
>This mail sent through IMP: http://horde.org/imp/
>
>_______________________________________________
>Python mailing list
>Python a lists.python.it
>http://lists.zope.it/cgi-bin/mailman/listinfo/python
>
>  
>




More information about the Python mailing list