Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created May 7, 2015 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ficapy/b743719e740ebbaf923f to your computer and use it in GitHub Desktop.
Save ficapy/b743719e740ebbaf923f to your computer and use it in GitHub Desktop.
列出2个相似的项目
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '15/5/7'
#没人比我更蛋疼了吧
a = [1,2,3,2]
from itertools import permutations
llist = len(a)
x = [((n+1)/(llist-1) if not (n+1)%(llist-1) else (n+1)/(llist-1)+1,n+1) for n,i in enumerate(permutations(a,2)) if i[0]==i[1]]
if x:
x = x[0]
print x[0],(x[0]-1)*(llist-1)+x[1]%(llist-1)+1 if x[1]%(llist-1) else llist
@ficapy
Copy link
Author

ficapy commented May 7, 2015

为了不用for循环也是够拼的

for i,n in enumerate(a):
for x,y in enumerate(a[i+1:]):
if n ==y:
print i+1,i+x+2
break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment