User Profile
Collapse
-
But this then only sorts by the day, and does not take into account month and year? -
Ordering a list by date substring
I am trying to write some code so it orders the list by the date in the substring.
I am trying to use 'sorted', or possibly .sort
Can anyone give me some pointers?
Code:mylist=["word_number_25_05_2011_XX", "word_number_14_04_2011_YY", "word_number_17_04_2011_XY"] sorted(mylist, key=lambda x: x[2:5]) print mylist
-
Sorry I possibly didn't explain too well!
It's close - although I already have both the lists ready to compare, and the second one is in the format I wrote, ie - A|1, B|2 etc.
Any way around that?Leave a comment:
-
Comparing lists
Say I have two lists:
list1 = [A, B, C, D, E]
list2 = [A|1, C|2, D|2, F|3]
I want to compare if the entries in list1 exist in the first half of the list2 entries, and print the whole outcome from list2.
So from this I would want an outcome of:
A|1, C|2, D|2
Thanks in advance. -
-
Printing duplicates from a text file
If i have a text file 'test.txt' containing:
1
1
1
2
2
3
I want it to print all the lines that are duplicates/matches.
So I would expect an output of
1
1
1
2
2
I was thinking something along the lines of:
Code:test = open("test.txt", 'r') for x in test: for y in test: if x==y:
No activity results to display
Show More
Leave a comment: