User Profile

Collapse

Profile Sidebar

Collapse
pystarter
pystarter
Last Activity: Oct 19 '12, 02:56 PM
Joined: May 22 '12
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • pystarter
    replied to Ordering a list by date substring
    But this then only sorts by the day, and does not take into account month and year?
    See more | Go to post

    Leave a comment:


  • pystarter
    started a topic Ordering a list by date substring

    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
    ...
    See more | Go to post

  • pystarter
    replied to Comparing lists
    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?
    See more | Go to post

    Leave a comment:


  • pystarter
    started a topic Comparing lists

    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.
    See more | Go to post

  • pystarter
    replied to Printing duplicates from a text file
    Thanks guys - great help!
    See more | Go to post

    Leave a comment:


  • pystarter
    started a topic Printing duplicates from a text file

    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:
    ...
    See more | Go to post
    Last edited by bvdet; May 22 '12, 02:18 PM. Reason: Add code tags
No activity results to display
Show More
Working...