|
Posted by ramesh03 |
|
|
Hi,
I am wrking on small project using Python2.6.Finally my list is like this. ['1:Rammmm,mmmm', '2:surr.rrrrr', '3:Sam ttttt', '1:qqqq qqqqqqq', '2:wwwwwwwwwww', '3:eeeeeeeee','4:tttttttt', '1:zzzzzzzzzzzzz', '2:xxxxxxxxx'] Here, i want to display all 1's in one line,all 2's in one line...etc, with pipe"|" as separator.It should be like this. {Rammmm,mmmm|qqqq qqqqqqq|zzzzzzzzzzzzz} {surr.rrrrr|wwwwwwwwwww|xxxxxxxxx} {Sam ttttt|eeeeeeeee} {tttttttt} How to achieve this in Python. Thanks. |
|
|
Posted by aabele |
|
|
Something like this.
def filter_list(query, data)
temp = []
for item in data:
if item.split(':')\[0\] == query:
temp.add(item)
return temp
mylist = ['1:Rammmm,mmmm', '2:surr.rrrrr', '3:Sam ttttt', '1:qqqq qqqqqqq', '2:wwwwwwwwwww', '3:eeeeeeeee','4:tttttttt', '1:zzzzzzzzzzzzz', '2:xxxxxxxxx']
myfilteredlist = filter_list('2', mylist)
|
|
|
Posted by aabele |
|
|
Sorry - use .append() instead of .add() and remove slashes before square brackets. I wrote this script ny hand - without python.
|
|
|
Posted by ramesh03 |
|
|
Thanks for your reply. aabele .
But my resulting stuff should be something like this. {Rammmm,mmmm|qqqq qqqqqqq|zzzzzzzzzzzzz} {surr.rrrrr|wwwwwwwwwww|xxxxxxxxx} {Sam ttttt|eeeeeeeee} {tttttttt} ThanQ. |
|
|
Posted by recursion |
|
|
hgi thanks for your information
|


